I have the following code on an update button in WinForms VS 2017.
private void btnEdit_Click(object sender, EventArgs e)
{
if (txtOrder.Text != "")
{
cmd = new SqlCommand("UPDATE AER_INBOUND_PLASTICS SET [STATUS]=@status,[DATE]=@date,[SOPO_NO]=@order,[SHIPPER]=@shipper,[VENDOR]=@vendor,[WAREHOUSE]=@warehouse,[COMMENTS]=@comments,[PURCH_PART_CODE]=@part1,[PURCH_PART_CODE_2]=@part2,GETDATE(),[MODIFIED_BY]=@user WHERE ID=@id", con);
con.Open();
cmd.Parameters.AddWithValue("@id", ID);
cmd.Parameters.AddWithValue("@status", comboBoxStatus.SelectedItem.ToString());
cmd.Parameters.AddWithValue("@date", txtLoadtime.Text);
cmd.Parameters.AddWithValue("@order", txtOrder.Text);
cmd.Parameters.AddWithValue("@shipper", txtShipper.Text);
cmd.Parameters.AddWithValue("@vendor", txtVendor.Text);
cmd.Parameters.AddWithValue("@warehouse", comboBoxWarehouse.SelectedItem.ToString());
cmd.Parameters.AddWithValue("@comments", txtComments.Text);
cmd.Parameters.AddWithValue("@part1", txtPart1.Text);
cmd.Parameters.AddWithValue("@part2", txtPart2.Text);
cmd.Parameters.AddWithValue("@user", Environment.UserName);
cmd.ExecuteNonQuery();
MessageBox.Show("Record Updated Successfully.");
con.Close();
dataGridView1.Refresh();
ClearData();
}
else
{
MessageBox.Show("Please Select Record to Update.");
}
}
The form loads correctly, and the textboxes are populated correctly from the DataGridView SelectedRow. When I modify the textboxes and click on the update button, I get the following error on the cmd.ExecuteNonQuery() line: Additional information: Incorrect syntax near '('.
I can't see any parentheses missing anywhere. I can't seem to track down where the error is in the update process.
What I have tried:
I scoured the code and did find a square bracket missing in the SqlCommand statement, but fixing that has not resolved the problem. I am following the instructions on this site (http://www.c-sharpcorner.com/uploadfile/1e050f/insert-update-and-delete-record-in-datagridview-c-sharp/)