-2

我正在尝试通过单击链接标签来显示我的表中的一些数据,但是当我启动应用程序时,我遇到了一些错误,例如:对象不包含标记的定义并且没有可访问的扩展方法错误

错误行: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();
        }
    }

谢谢

4

1 回答 1

0
     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();
    }
}
于 2021-09-10T18:54:01.627 回答