0

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

2
Contributors
1
Reply
4
Views
6 Years
Discussion Span
Last Post by shakeb@techwave
0

try this ..I hope it will work ,,change feils acording to your requirment.
Thanx Shakeb khan

"INSERT INTO [Task$] ([CLIENTS], [ASSIGNMENTS], [STATUS], [ELAPSED TIME]) VALUES( '" + cbClient.Text + "', '" + cbAssignment.Text + "', 'IDLE', '0')

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.