Hi guys,
I've been cracking on with this project for a few days now and had lots of useful pointers to help along the way.
I've now hit a little snag where I think I have written the correct update Statement but It seems to error at the last point.
The Code is the following:
if (radioButton1.Checked == true)
{
//Creates new versions of the Connection string and Data Set//
con = new System.Data.OleDb.OleDbConnection();
ds = new DataSet();
//The actual connection to the database//
con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = E:/Orders1.mdb";
//Open the Connection to the Database//
con.Open();
//The SQL UPDATE String you need to pass into the Data Adapter to collect the information//
string UpdateCashOrderSQL = "UPDATE cashOrders SET cashQTY = '" + txtBoxQTY.Text + "', cashDescription = '" + txtBoxDesc.Text + "', cashSupplier = '" + txtBoxSupplier.Text + "' , cashDate = '" + dateTimePicker1.Text + "', cashCost = '" + txtBoxCost.Text + "', cashSell = '" + txtBoxSell.Text + "' WHERE CashAccRef_FKID = '" + txtAccRef.Text + "' AND cashID = '" + dataGridView2.SelectedCells[0].Value.ToString() +"' ";
//Creates a new version of the Data Adapater which passed the SQL and Connection information//
da = new System.Data.OleDb.OleDbDataAdapter(UpdateCashOrderSQL, con);
//Data Adapater (da) uses the Insert Command along with the SQL Querey & Connection Details//
da.UpdateCommand = con.CreateCommand();
da.UpdateCommand.CommandText = UpdateCashOrderSQL;
da.UpdateCommand.ExecuteNonQuery();
//Closes the connection//
con.Dispose();
//Shows End User the Account has been added//
MessageBox.Show("Customer Account updated");
}
The part I think is causing the trouble is...
AND cashID = '" + dataGridView2.SelectedCells[0].Value.ToString() +"' ";
even though the form loads and when debugging seems to select the correct information it still errors at the last hurdle stating...
Data type mismatch in criteria expression. (See Screenshot)
Look forward to some responses and thanks in advance.
Regards
Mark.