我正在尝试通过单击链接标签来显示我的表中的一些数据,但是当我启动应用程序时,我有一些错误,如:对象不包含标记的定义,没有可访问的扩展方法错误
错误行:int appID = (LinkLabel)sender.Tag;
代码你请帮我解决这个错误,或者如果你有其他的想法来获得ID
下面是我的代码:
private void ShowAppointmentDetail(object sender, EventArgs e)
{
int appID = (LinkLabel)sender.Tag;
SqlCommand sql = new SqlCommand("select * from RDV whereID_RDV = {appID}");
DataTable dt = new DataTable();
SqlDataAdapter sda = new SqlDataAdapter(sql);
sda.Fill(dt);
if (dt.Rows.Count > 0)
{
DataRow row = dt.Rows[0];
{
frmManageAppointment withBlock = new frmManageAppointment();
withBlock.Nom.Text = row["Nom"].ToString();
withBlock.Prénom.Text = row["Prénom"].ToString();
withBlock.NUM.Text = row["Num"].ToString();
withBlock.date.Text = row["DateRDV"].ToString();
withBlock.ShowDialog();
}
DisplayCurrentDate();
}
}
谢谢
private void ShowAppointmentDetail(object sender, EventArgs e)
{
Was : int appID = (LinkLabel)sender.Tag;
Answer : var appID = (sender as LinkLabel).Tag;
SqlCommand sql = new SqlCommand("select * from RDV whereID_RDV = {appID}");
DataTable dt = new DataTable();
SqlDataAdapter sda = new SqlDataAdapter(sql);
sda.Fill(dt);
if (dt.Rows.Count > 0)
{
DataRow row = dt.Rows[0];
{
frmManageAppointment withBlock = new frmManageAppointment();
withBlock.Nom.Text = row["Nom"].ToString();
withBlock.Prénom.Text = row["Prénom"].ToString();
withBlock.NUM.Text = row["Num"].ToString();
withBlock.date.Text = row["DateRDV"].ToString();
withBlock.ShowDialog();
}
DisplayCurrentDate();
}
}