Update database through TableAdapter

426 Views Asked by At

I'm using the table adapter in C# where I created a DataGridView. When I double click a row, I am displaying all the cells in the row in textboxes in a different Form. After I edit the textboxes and click my save button, I would like to take the values from the textboxes and replace them in the database. I can see the changes on the DataGrid, however I am not able to save them in the database.

private void InventoryData_CellDoubleClick(object sender, DataGridViewCellEventArgs e)

{
   //make new form and display them there
   ViewInventoryItem ViewItem = new ViewInventoryItem();

   ViewItem.textBox1.Text = this.InventoryData.CurrentRow.Cells[1].Value.ToString();
   ViewItem.textBox2.Text = this.InventoryData.CurrentRow.Cells[2].Value.ToString();
   ViewItem.textBox3.Text = this.InventoryData.CurrentRow.Cells[3].Value.ToString();
   ViewItem.ShowDialog();

   if (ViewItem.DialogResult == DialogResult.OK)
   {
       //save button was pressed
       this.InventoryData.CurrentRow.Cells[0].Value = ViewItem.textBox1.Text;
       this.InventoryData.CurrentRow.Cells[1].Value = ViewItem.textBox2.Text;
       this.InventoryData.CurrentRow.Cells[2].Value = ViewItem.textBox3.Text;

       this.Validate();
       this.InventoryData.EndEdit();                 
       this.booksTableAdapter.Update(this.InventoryDataSet.Books);   
   }
             
}
1

There are 1 best solutions below

0
Raj On BEST ANSWER

Found the problem. In the Dataset the Table had only Fill and Get Data. Even after selecting the Wizard to add the other statements it was failing. After adding the UpdateQuery manually, the code works without issues. Thank you Crowcoder for pointing me in the right direction.