I am trying to insert record from c# window form to access 2007 database, but I am getting this error -
Error: Syntax error in INSERT INTO statement. A first chance exception of type 'System.Data.OleDb.OleDbException' occurred in System.Data.dll
But I am not seeing anything wrong with my code-
try
{
string sday = "Sun";
s1 = comboBox180.SelectedItem.ToString();
t1 = comboBox10.SelectedItem.ToString();
d1 = comboBox17.SelectedItem.ToString();
string bla="XYZ";
aCommand5 = new OleDbCommand("INSERT INTO weekly(batch_code,day,period_no,teacher1,time1,teacher2,time2,teacher3,time3,teacher4,time4,teacher5,time5,teacher6,time6,teacher7,time7,teacher8,time8,teacher9,time9,teacher10,time10,teacher11,time11,teacher12,time12) VALUES ('" + code + "','" +sday+"','" + no_of_period + "','" + t1 + "','" + d1 + "','"+bla+"','"+bla+"','"+bla+"','"+bla+"','"+bla+"','"+bla+"','"+bla+"','"+bla+"','"+bla+"','"+bla+"','"+bla+"','"+bla+"','"+bla+"','"+bla+"','"+bla+"','"+bla+"','"+bla+"','"+bla+"','"+bla+"','"+bla+"','"+bla+"','"+bla+"')", main_connection);
int check = aCommand5.ExecuteNonQuery();
if (check == 1)
{
MessageBox.Show("Data Saved");
}
}
catch (OleDbException oldex)
{
Console.WriteLine("Error: {0}", oldex.Errors[0].Message);
}
t1 and d1 both are string variable.