Syntax error in INSERT INTO statement.

M

me

This is driving me insane!!

I have a very simple Insert statement that is blowing out with a Syntax
error. First, here is my code - I have stripped out all of the dynamic
column names and hard-coded the values just to try and identify the problem:

Dim myConn1 As New OleDbConnection(AppSettings("myConnectionString"))
Dim mySQL1 As String = "INSERT INTO SECTION (ClientID, TownID ) VALUES (
'460', '4' )"
Dim cmd1 As New OleDbCommand(mySQL1, myConn1)
myConn1.Open()
cmd1.ExecuteNonQuery()
myConn1.Close()

I have tried removing the single quotes, putting brackets around the column
names, and all to no avail. I have also verified security rights on the
database and actually have a very similar Insert statement that runs before
this page that works just fine?!? Here is the error page I am getting:


Server Error in '/myApp' Application.
--------------------------------------------------------------------------------

Syntax error in INSERT INTO statement.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.Data.OleDb.OleDbException: Syntax error in INSERT
INTO statement.

Source Error:


Line 75: myConn1.Open()
Line 76: cmd1.ExecuteNonQuery()
Line 77: myConn1.Close()


Source File: D:\Inetpub\myApp\addSection.aspx.vb Line: 76

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
myApp.addSection.button1_Click(Object sender, EventArgs e) in
D:\Inetpub\wls2\addSection.aspx.vb:76
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) +5102
 
M

Miha Markic

Looks like you are accessing a JET database from an asp.net application,
correct?
Make sure the user running asp.net application has enough privileges to
modfiy jet files, specially NTFS.

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

me said:
This is driving me insane!!

I have a very simple Insert statement that is blowing out with a Syntax
error. First, here is my code - I have stripped out all of the dynamic
column names and hard-coded the values just to try and identify the
problem:

Dim myConn1 As New OleDbConnection(AppSettings("myConnectionString"))
Dim mySQL1 As String = "INSERT INTO SECTION (ClientID, TownID ) VALUES (
'460', '4' )"
Dim cmd1 As New OleDbCommand(mySQL1, myConn1)
myConn1.Open()
cmd1.ExecuteNonQuery()
myConn1.Close()

I have tried removing the single quotes, putting brackets around the
column names, and all to no avail. I have also verified security rights
on the database and actually have a very similar Insert statement that
runs before this page that works just fine?!? Here is the error page I am
getting:


Server Error in '/myApp' Application.
--------------------------------------------------------------------------------

Syntax error in INSERT INTO statement.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.Data.OleDb.OleDbException: Syntax error in
INSERT INTO statement.

Source Error:


Line 75: myConn1.Open()
Line 76: cmd1.ExecuteNonQuery()
Line 77: myConn1.Close()


Source File: D:\Inetpub\myApp\addSection.aspx.vb Line: 76

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
myApp.addSection.button1_Click(Object sender, EventArgs e) in
D:\Inetpub\wls2\addSection.aspx.vb:76
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) +5102
 
G

Guest

me,

The problem is that SECTION is a reserved keyword in Access.

You need to enclose Access reserved keywords in square brackets: [SECTION]

Kerry Moorman


me said:
This is driving me insane!!

I have a very simple Insert statement that is blowing out with a Syntax
error. First, here is my code - I have stripped out all of the dynamic
column names and hard-coded the values just to try and identify the problem:

Dim myConn1 As New OleDbConnection(AppSettings("myConnectionString"))
Dim mySQL1 As String = "INSERT INTO SECTION (ClientID, TownID ) VALUES (
'460', '4' )"
Dim cmd1 As New OleDbCommand(mySQL1, myConn1)
myConn1.Open()
cmd1.ExecuteNonQuery()
myConn1.Close()

I have tried removing the single quotes, putting brackets around the column
names, and all to no avail. I have also verified security rights on the
database and actually have a very similar Insert statement that runs before
this page that works just fine?!? Here is the error page I am getting:


Server Error in '/myApp' Application.
--------------------------------------------------------------------------------

Syntax error in INSERT INTO statement.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.Data.OleDb.OleDbException: Syntax error in INSERT
INTO statement.

Source Error:


Line 75: myConn1.Open()
Line 76: cmd1.ExecuteNonQuery()
Line 77: myConn1.Close()


Source File: D:\Inetpub\myApp\addSection.aspx.vb Line: 76

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
myApp.addSection.button1_Click(Object sender, EventArgs e) in
D:\Inetpub\wls2\addSection.aspx.vb:76
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) +5102
 
M

me

That was it!!!!

Thanks a GAZILLION!



Kerry Moorman said:
me,

The problem is that SECTION is a reserved keyword in Access.

You need to enclose Access reserved keywords in square brackets:
[SECTION]

Kerry Moorman


me said:
This is driving me insane!!

I have a very simple Insert statement that is blowing out with a Syntax
error. First, here is my code - I have stripped out all of the dynamic
column names and hard-coded the values just to try and identify the
problem:

Dim myConn1 As New OleDbConnection(AppSettings("myConnectionString"))
Dim mySQL1 As String = "INSERT INTO SECTION (ClientID, TownID ) VALUES (
'460', '4' )"
Dim cmd1 As New OleDbCommand(mySQL1, myConn1)
myConn1.Open()
cmd1.ExecuteNonQuery()
myConn1.Close()

I have tried removing the single quotes, putting brackets around the
column
names, and all to no avail. I have also verified security rights on the
database and actually have a very similar Insert statement that runs
before
this page that works just fine?!? Here is the error page I am getting:


Server Error in '/myApp' Application.
--------------------------------------------------------------------------------

Syntax error in INSERT INTO statement.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.Data.OleDb.OleDbException: Syntax error in
INSERT
INTO statement.

Source Error:


Line 75: myConn1.Open()
Line 76: cmd1.ExecuteNonQuery()
Line 77: myConn1.Close()


Source File: D:\Inetpub\myApp\addSection.aspx.vb Line: 76

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
myApp.addSection.button1_Click(Object sender, EventArgs e) in
D:\Inetpub\wls2\addSection.aspx.vb:76
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)
+5102
 
G

Greg Burns

Wrap SECTION in brackets;

INSERT INTO [SECTION] (ClientID, TownID ) VALUES ('460', '4' )"

If you make this some query in Access it will wrap it in brackets if your
table is named SECTION. Must be a reserved keyword.

Greg


me said:
This is driving me insane!!

I have a very simple Insert statement that is blowing out with a Syntax
error. First, here is my code - I have stripped out all of the dynamic
column names and hard-coded the values just to try and identify the
problem:

Dim myConn1 As New OleDbConnection(AppSettings("myConnectionString"))
Dim mySQL1 As String = "INSERT INTO SECTION (ClientID, TownID ) VALUES (
'460', '4' )"
Dim cmd1 As New OleDbCommand(mySQL1, myConn1)
myConn1.Open()
cmd1.ExecuteNonQuery()
myConn1.Close()

I have tried removing the single quotes, putting brackets around the
column names, and all to no avail. I have also verified security rights
on the database and actually have a very similar Insert statement that
runs before this page that works just fine?!? Here is the error page I am
getting:


Server Error in '/myApp' Application.
--------------------------------------------------------------------------------

Syntax error in INSERT INTO statement.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.Data.OleDb.OleDbException: Syntax error in
INSERT INTO statement.

Source Error:


Line 75: myConn1.Open()
Line 76: cmd1.ExecuteNonQuery()
Line 77: myConn1.Close()


Source File: D:\Inetpub\myApp\addSection.aspx.vb Line: 76

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
myApp.addSection.button1_Click(Object sender, EventArgs e) in
D:\Inetpub\wls2\addSection.aspx.vb:76
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) +5102
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top