Hi guys, Needing some help here please.
I have a 'Save button' setup on my form which seems to be working perfectly. It allows vales to be taken from text boxes and then presented on a datagrid view and also saved to the underlying databse.
The Code for this save button is below:
private void btnSaveAcc_Click(object sender, EventArgs e)
{
System.Data.OleDb.OleDbCommandBuilder cb;
cb = new System.Data.OleDb.OleDbCommandBuilder(cashDA);
DataRow DR = cashCustomersDS.Tables[0].NewRow();
DR["CashAccRef"] = Int64.Parse(txtBoxAccRef.Text);
DR["CashName"] = txtBoxName.Text.ToString();
DR["CashAddress1"] = txtBoxAddr1.Text.ToString();
DR["CashAddress2"] = txtBoxAddr2.Text.ToString();
DR["CashTown"] = txtBoxTown.Text.ToString();
DR["CashAddress3"] = txtBoxCounty.Text.ToString();
DR["CashAddress5"] = txtBoxPostCode.Text.ToString();
cashCustomersDS.Tables[0].Rows.Add(DR);
cashDA.Update(cashCustomersDS, "cashCustomers");
MessageBox.Show("Customer Added");
}
Now... the issues seems to be with the 'Delete' Button. The When clicking on a row in the gridview the values are populated into the text boxes (incase of editing is needed) but when clicking Delete I receive an error on the 'cashDA.Update' line.
Value cannot be Null.
Parameter Name: dataTable.
The code for the 'Delete' button is as follows:
private void btnOrderDelete_Click(object sender, EventArgs e)
{
System.Data.OleDb.OleDbCommandBuilder cb;
cb = new System.Data.OleDb.OleDbCommandBuilder(cashDA);
if (dataGridView2.SelectedRows.Count > 0)
{
cashOrdersTable.Rows.RemoveAt(dataGridView2.SelectedRows[0].Index);
cashDA.Update(cashOrdersDS.Tables["cashOrders"]);
MessageBox.Show("Record Deleted");
}
else
{
MessageBox.Show("Please Select a row");
}
}
Now, as long as I take out the following line... ''cashDA.Update(cashOrdersDS.Tables["cashOrders"]);'' the code seems to run fine and removes a line from the gridview. So it seems like there is an issue with updating the underlying database.
Any help on this would be great as I've been scratching my head on this all Friday.
regards
Mark.