Hi Guys,
The reason for my message was to do with UPDATE and DELETE Statements from within C# when contacting a MDB file.
I currently have the INSERT INTO SQL Query working perfectly
The Code I used for this is below:
else if (radioButton2.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 INSERT INTO String you need to pass into the Data Adapter to collect the information//
string AddCustomerSQL = "INSERT INTO PrintedCustomers(PrintedAccRef, pCashName, pCashAddress1, pCashAddress2, pCashTown, pCashAddress3,pCashAddress4 ) " +
" VALUES('" + txtAccRef.Text + "', '" + txtAccName.Text + "','" + txtAccAddr1.Text + "' ,'" + txtAccAddr2.Text + "' , '" + txtAccTown.Text + "' , '" + txtAccCounty.Text + "' , '" + txtAccPostCode.Text + "')";
//Creates a new version of the Data Adapater which passed the SQL and Connection information//
da = new System.Data.OleDb.OleDbDataAdapter(AddCustomerSQL, con);
//Data Adapater (da) uses the Insert Command along with the SQL Querey & Connection Details//
da.InsertCommand = new OleDbCommand(AddCustomerSQL, con);
da.InsertCommand.ExecuteNonQuery();
//Closes the connection//
con.Dispose();
//Shows End User the Account has been added//
MessageBox.Show("Printed Account Added");
BUT... now its come to the UPDATE and DELETE Query i'm not too sure on how to handle it. Currently I have the following for my UPDATE Code:
private void btnEditCashAcc_Click(object sender, EventArgs e)
{
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 INSERT INTO String you need to pass into the Data Adapter to collect the information//
string UpdateCustomerSQL = "UPDATE cashCustomers (CashAccRef, CashName, CashAddress1, CashAddress2, CashTown, CashAddress3,CashAddress4 ) " +
" VALUES('" + txtAccRef.Text + "', '" + txtAccName.Text + "','" + txtAccAddr1.Text + "' ,'" + txtAccAddr2.Text + "' , '" + txtAccTown.Text + "' , '" + txtAccCounty.Text + "' , '" + txtAccPostCode.Text + "')";
//Creates a new version of the Data Adapater which passed the SQL and Connection information//
da = new System.Data.OleDb.OleDbDataAdapter(UpdateCustomerSQL, con);
//Data Adapater (da) uses the Insert Command along with the SQL Querey & Connection Details//
da.UpdateCommand = con.CreateCommand();
da.UpdateCommand.CommandText = UpdateCustomerSQL;
da.UpdateCommand.ExecuteNonQuery();
//Closes the connection//
con.Dispose();
//Shows End User the Account has been added//
MessageBox.Show("Customer Account updated");
}
}
When Debugging it seems to follow through with the correct details within the Locals window but error's saying my SYNTAX is incorrect in the UPDATE Statment (Syntax error in UPDATE statement.).
I hope you can help me out once again as I would love to get this project finished and under my belt.
I look forward to hearing from you
Regards
Mark.