mardi 31 mars 2015

Deleting Specific Data From Database Row (C#)

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();
}

Aucun commentaire:

Enregistrer un commentaire