【问题标题】:C# programming with window forms使用窗口窗体进行 C# 编程
【发布时间】:2019-04-19 15:36:29
【问题描述】:
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");

当我运行此代码时,我的整个数据库表都会使用当前值更新,我无法理解问题

【问题讨论】:

    标签: forms window


    【解决方案1】:

    “其中 id = ID”条件始终为真,因此所有记录都会受到影响。您需要为“ID”实际设置一个值。也许你需要写

    "where id =" + ID.ToString()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-05-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-03-28
      • 1970-01-01
      • 2011-05-24
      相关资源
      最近更新 更多