Hi , i am getting syntax error in INSERT INTO statement. getting this error on cmdobj.ExecuteNonQuery();
string connectionstring = @"Provider=Microsoft.ACE.OLEDB.12.0;
Data Source=D:\website\AddContact.xlsx; Extended Properties=""Excel 8.0;HDR=Yes"";";
OleDbConnection conobj = new OleDbConnection(connectionstring);
string Query = "INSERT INTO [Sheet1$](Fname, LName,PhoneNo,Email-ID) values (" + TextBox4.Text + ",'" + TextBox1.Text + "','" + TextBox2.Text + "','" + TextBox3.Text + "')";
OleDbCommand cmdobj = new OleDbCommand(Query, conobj);
conobj.Open();
cmdobj.ExecuteNonQuery();
conobj.Close();
Stack Trace:
[OleDbException (0x80040e14): Syntax error in INSERT INTO statement.]
System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult) +267
System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult) +192
System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult) +48
System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method) +106
System.Data.OleDb.OleDbCommand.ExecuteNonQuery() +108
Addcontact.Button1_Click(Object sender, EventArgs e) in d:\WebSite\Addcontact.aspx.cs:67
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +105
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +107
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5087