Hi frnds,
I am working on a project in which one of the form has a datagridview, I was successful in retrieving the table from the database.Now that I want to edit the records on this datagrid and save them back in the physical database.I have been try to do this in a number of ways but getting some or other error pops up.
The following is the code I have used.
myUpdateCommand.CommandText = @"UPDATE Inventory SET ItemDescription = ?, ItemNumber = ?, ItemCode = ?, ItemType = ?, Location = ?, Unit = ?, OurPrice = ?, StudentPrice = ?, PONumber = ?, Quantity = ? WHERE (ItemDescription = ?) AND (ItemNumber = ?) AND (ItemType = ?) AND (Location = ?) AND (Unit = ?) AND (OurPrice = ?) AND (StudentPrice = ?) AND (PONumber = ?) AND (Quantity = ?)";
this.myUpdateCommand.Connection = this.myOleDbConnection;
this.myUpdateCommand.Parameters.Add(new OleDbParameter("ItemDescription",this.dataGridView 1.CurrentRow.Cells[0].Value.ToString()));
this.myUpdateCommand.Parameters.Add(new OleDbParameter("ItemNumber",this.dataGridView1.Cur rentRow.Cells[1].Value.ToString()));
this.myUpdateCommand.Parameters.Add(new OleDbParameter("ItemCode",this.dataGridView1.Curre ntRow.Cells[2].Value.ToString()));
this.myUpdateCommand.Parameters.Add(new OleDbParameter("ItemType",this.dataGridView1.Curre ntRow.Cells[3].Value.ToString()));
this.myUpdateCommand.Parameters.Add(new OleDbParameter("Location",this.dataGridView1.Curre ntRow.Cells[4].Value.ToString()));
this.myUpdateCommand.Parameters.Add(new OleDbParameter("DateItemCreated",this.dataGridView 1.CurrentRow.Cells[5].Value.ToString()));
this.myUpdateCommand.Parameters.Add(new OleDbParameter("Unit",this.dataGridView1.CurrentRo w.Cells[6].Value.ToString()));
this.myUpdateCommand.Parameters.Add(new OleDbParameter("OurPrice",this.dataGridView1.Curre ntRow.Cells[7].Value.ToString()));
this.myUpdateCommand.Parameters.Add(new OleDbParameter("StudentPrice",this.dataGridView1.C urrentRow.Cells[8].Value.ToString()));
this.myUpdateCommand.Parameters.Add(new OleDbParameter("PONumber",this.dataGridView1.Curre ntRow.Cells[9].Value.ToString()));
this.myUpdateCommand.Parameters.Add(new OleDbParameter("Quantity",this.dataGridView1.Curre ntRow.Cells[10].Value.ToString()));
this.myOleDbDataAdapter.UpdateCommand = myUpdateCommand;
DataSet myChangedDataSet = myDataSet.GetChanges();
this.myDataSet.GetChanges();
btnSave.Enabled = false;
this.myOleDbDataAdapter.Update(myDataSet, "Inventory");
Could someone help me out with this and let me know what statement is causing the problem or is it the entire technique thats causing the problem?
Thank You in advance!!!