This code is part off a bigger function I hope Ive copied the {} properly balancing them out. I have a dataGridView which has been updated this percedure is simply to write the changes back into a blanked out table?
OleDbCommand cmd = new OleDbCommand();
for (int ii = 0; ii < dataGridView1.Rows.Count; ii++)
{
DataGridViewRow dr = dataGridView1.Rows[ii];
if (dr.Selected == true)
{
string connetionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\temp\\Set.mdb;Persist Security Info=False";
try
{
int number = 0; //possible empty statment warning next line
using (OleDbConnection connection = new OleDbConnection(connetionString))
{
sql = "Insert into EnableOne SET Property=@var1, Pvalue=@var2, Pdefault=@var3, PType=@var4";
connection.Open(); //This fail's to compile connection does not exist in the current context
using (OleDbCommand cmd1 = new OleDbCommand(sql, connection))//This fail's to compile connection does not exist in the current context
{
number = dataGridView1.CurrentCell.RowIndex;
int numr = 0;
numr = dataGridView1.Rows.Count;
{
for (int x = 0; x < numr; x++)
{
cmd1.Parameters.Add(new OleDbParameter("@var1", dataGridView1.Rows[x].Cells[0].Value.ToString()));
cmd1.Parameters.Add(new OleDbParameter("@var2", dataGridView1.Rows[x].Cells[1].Value.ToString()));
cmd1.Parameters.Add(new OleDbParameter("@var3", dataGridView1.Rows[x].Cells[2].Value.ToString()));
cmd1.Parameters.Add(new OleDbParameter("@var4", dataGridView1.Rows[x].Cells[3].Value.ToString()));
cmd1.CommandText = sql;
cmd1.ExecuteNonQuery();
}
}
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
}
}
The above code produces this error
Error System.Data.OleDb.OleDbException (0x80040E14): Syntax error in INSERT INTO statement.
at System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResult hr) at System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method) at System.Data.OleDb.OleDbCommand.ExecuteNonQuery() at CrewCheifSettingsBeta3.Form1.updater(String table) in