Hi, here is my code.
String sConnectionString = "Provider=Microsoft.Ace.OLEDB.12.0;Data Source=" + excelfile + ";Extended Properties=Excel 12.0;";
OleDbConnection olecon = new OleDbConnection(sConnectionString);
olecon.Open();
//string stdemo;
string olestr;
olestr = "Insert Into [Sheet1$] (Buyer,Salutation,Company,AddressLine1,City,State,Zip,date) Values (?,?,?,?,?,?,?,?)";
// OleDbCommand olecmd;
using (OleDbConnection conn = new OleDbConnection(sConnectionString))
{
for (int i = 0; i < dttmp.Rows.Count; i++)
{
using (OleDbCommand cmd1 = new OleDbCommand(olestr, conn))
{
cmd1.Parameters.Clear();
cmd1.CommandType = CommandType.Text;
cmd1.Parameters.AddWithValue("Buyer", dttmp.Rows[i]["Buyer"]);
cmd1.Parameters.AddWithValue("Salutation", dttmp.Rows[i]["Salutation"]);
cmd1.Parameters.AddWithValue("Company", dttmp.Rows[i]["Company"]);
cmd1.Parameters.AddWithValue("AddressLine1", dttmp.Rows[i]["AddressLine1"]);
cmd1.Parameters.AddWithValue("City", dttmp.Rows[i]["City"]);
cmd1.Parameters.AddWithValue("State", dttmp.Rows[i]["State"]);
cmd1.Parameters.AddWithValue("Zip", dttmp.Rows[i]["Zip"]);
cmd1.Parameters.AddWithValue("date", dttmp.Rows[i]["date"]);
conn.Open();
cmd1.ExecuteNonQuery();
}
}
}While excute the cmd1 i got the Error like : Syntax error in Insert into statement
Can anyone please give me the solutions.
Thanks in Advance.