数据库中的记录未更新
本文关键字:更新 记录 数据库 | 更新日期: 2023-09-27 18:36:12
我无法更新数据库中的记录。
我的代码如下:
private void update_Click(object sender, EventArgs e)
{
con.Open();
try
{
string strQuery = "UPDATE test_name SET Test_Name = @name, Price = @price, Lab_Price = @lprice, normal_value_child = @child, normal_value_men = @men, normal_value_women = @women, notes = @note, unit = @un, SubGroup = @sub, MainGroup = @main" +
"WHERE Test_Id = @tstID";
using (System.Data.SqlServerCe.SqlCeCommand cmdSelect = new System.Data.SqlServerCe.SqlCeCommand(strQuery, con))
{
cmdSelect.Parameters.AddWithValue("@tstID", richTextBox2.Text);
cmdSelect.Parameters.AddWithValue("@name", richTextBox1.Text);
cmdSelect.Parameters.AddWithValue("@price", richTextBox7.Text);
cmdSelect.Parameters.AddWithValue("@lprice", richTextBox8.Text);
cmdSelect.Parameters.AddWithValue("@child", richTextBox5.Text);
cmdSelect.Parameters.AddWithValue("@men", richTextBox4.Text);
cmdSelect.Parameters.AddWithValue("@women", richTextBox3.Text);
cmdSelect.Parameters.AddWithValue("@note", richTextBox9.Text);
cmdSelect.Parameters.AddWithValue("@un", richTextBox6.Text);
cmdSelect.Parameters.AddWithValue("@sub", comboBox2.Text);
cmdSelect.Parameters.AddWithValue("@main", comboBox1.Text);
cmdSelect.ExecuteNonQuery();
updatedb();
con.Close();
}
}
catch (Exception ex)
{
}
this.test_nameTableAdapter2.Fill(this.datalabDataSet14.test_name);
MessageBox.Show("Updated Successfully");
}
}
我不明白有什么问题。
在 WHERE 之前添加空格:
string strQuery = "UPDATE test_name SET Test_Name = @name, Price = @price, Lab_Price = @lprice, normal_value_child = @child, normal_value_men = @men, normal_value_women = @women, notes = @note, unit = @un, SubGroup = @sub, MainGroup = @main" +
" WHERE Test_Id = @tstID";