Forms 用窗口窗体进行C#编程

Forms 用窗口窗体进行C#编程,forms,window,Forms,Window,当我运行这段代码时,我的整个数据库表都会用当前值更新,我无法理解这个问题,因为“where id=id”条件始终为真,所以所有记录都会受到影响。您需要为“ID”实际设置一个值。也许你需要写信 private void dataGridView1_RowHeaderMouseClick_1(object sender, DataGridViewCellMouseEventArgs e) { int ID = Convert.ToInt32(dataGrid

当我运行这段代码时,我的整个数据库表都会用当前值更新,我无法理解这个问题,因为“where id=id”条件始终为真,所以所有记录都会受到影响。您需要为“ID”实际设置一个值。也许你需要写信

private void dataGridView1_RowHeaderMouseClick_1(object sender, DataGridViewCellMouseEventArgs e)
        {
            int  ID = Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString());  
            txtName.Text = dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString();  
            txtFname.Text = dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString();
            txtAddress.Text = dataGridView1.Rows[e.RowIndex].Cells[3].Value.ToString();

        }

        private void btnEdit_Click(object sender, EventArgs e)
        {
            SqlCommand cmd = new SqlCommand("Update student set  name ='"+txtName.Text+"', fathername= '"+txtFname.Text+"', address= '"+txtAddress.Text+"' where id = ID", con);
            con.Open();
            cmd.ExecuteNonQuery();
            con.Close();
            Display();
            MessageBox.Show("Record is Updated");
"where id =" + ID.ToString()