I'm trying to allow (a user), to delete data from the database and replace it with updated information.
The problem I run into is this:
SqlException was unhandled: Incorrect syntax near ','.
And this error appears at the first: sqlcmd.ExecuteNonQuery()
Here is the full code for the "Apply Edits" button:
private void applybtn_Click(object sender, EventArgs e)
{
Connection();
sqlconnection.Open();
sqlcmd = new SqlCommand("DELETE Item, Quantity, description, datasheet FROM inventory_table WHERE id= " + ID, sqlconnection);
sqlcmd.ExecuteNonQuery();
sqlcmd = new SqlCommand("UPDATE inventory_table SET Item = @Item, Quantity = @Quantity, description = @description, datasheet = @datasheet "+
"WHERE id= " + ID, sqlconnection);
sqlcmd.Parameters.AddWithValue("@Item", this.txtbx1.Text);
sqlcmd.Parameters.AddWithValue("@Quantity", this.txtbx2.Text);
sqlcmd.Parameters.AddWithValue("@description", this.txtbx3.Text);
sqlcmd.Parameters.AddWithValue("@datasheet", this.txtbx4.Text);
sqlcmd.ExecuteNonQuery();
sqlconnection.Close();
}
Try this
private void applybtn_Click(object sender, EventArgs e)
{
Connection();
sqlconnection.Open();
sqlcmd = new SqlCommand("DELETE FROM inventory_table WHERE id= " + ID, sqlconnection);
sqlcmd.ExecuteNonQuery();
sqlcmd = new SqlCommand("UPDATE inventory_table SET Item = @Item, Quantity = @Quantity, description = @description, datasheet = @datasheet "+
"WHERE id= " + ID, sqlconnection);
sqlcmd.Parameters.AddWithValue("@Item", this.txtbx1.Text);
sqlcmd.Parameters.AddWithValue("@Quantity", this.txtbx2.Text);
sqlcmd.Parameters.AddWithValue("@description", this.txtbx3.Text);
sqlcmd.Parameters.AddWithValue("@datasheet", this.txtbx4.Text);
sqlcmd.ExecuteNonQuery();
sqlconnection.Close();
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.