我得到了这个sqlException:
','附近的语法不正确。
newConnection.ConnectionM();
SqlCommand cmd = SqlConnectionOLTP.cn.CreateCommand();
cmd.CommandText = "Update Cost SET ActualAmount=@actualamount,FlagAdjustment=@flag, Date=@date where ProjectID=@projectid, PropertyID=@propertyid, CostCategoryID=@costcategoryid";
cmd.Parameters.AddWithValue("@actualamount", textBoxAmount.Text);
cmd.Parameters.AddWithValue("@flag", flag);
cmd.Parameters.AddWithValue("@date", dateTimePickerDate.Text);
cmd.Parameters.AddWithValue("@projectid", ProjectID);
cmd.Parameters.AddWithValue("@propertyid", PropertyID);
cmd.Parameters.AddWithValue("@costcategoryid", CostCatID);
cmd.ExecuteNonQuery();
SqlConnectionOLTP.cn.Close();
MessageBox.Show("Saved", "Save", MessageBoxButtons.OK, MessageBoxIcon.None);
答案 0 :(得分:1)
条件应使用和或 OR 或您要应用的条件分隔的逗号。
我使用和条件,如下所示:
newConnection.ConnectionM();
SqlCommand cmd = SqlConnectionOLTP.cn.CreateCommand();
cmd.CommandText = "Update Cost SET ActualAmount=@actualamount,FlagAdjustment=@flag, Date=@date where ProjectID=@projectid and PropertyID=@propertyid and CostCategoryID=@costcategoryid";
cmd.Parameters.AddWithValue("@actualamount", textBoxAmount.Text);
答案 1 :(得分:0)
我认为你应该写出正确的语法
cmd.CommandText = "Update Cost SET ActualAmount=@actualamount,FlagAdjustment=@flag, Date=@date where ProjectID=@projectid and PropertyID=@propertyid and CostCategoryID=@costcategoryid";
我希望它对你有用