c#数据库
private void button2_Click(object sender, EventArgs e){
string p1 = productIDTextBox.Text.Trim();
string p2 = productNameTextBox.Text.Trim();
string p3 = supplierNameTextBox.Text.Trim();
if (p1 == "")
{
MessageBox.Show("请选择要修改的产品", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
SqlConnection thisConection = new SqlConnection(@"server=(local);integrated security=True;database=Oms");
string str = "update products set productName='"+p2+"',supplierName='"+p3+"' where productId='"+p1+"';" ;
thisConection.Open();
SqlCommand thisCommand = thisConection.CreateCommand();
= str;
try
{
thisCommand.ExecuteNonQuery();
this.productsTableAdapter.Fill(this.omsDataSet.Products);
MessageBox.Show("产品更新成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
String str1 = ex.Message;
thisConection.Close();
MessageBox.Show("产品编号不能修改", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
我的意思是要实现“修改Button”,因为ID要作为条件,所以不能修改,若修改,则弹出错误。但是实现不了,
结果是不能修改ID,但弹出“产品更新成功”
求解,谢谢。