473,396 Members | 1,749 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Please help : System.Data.OleDb.OleDbException: Syntaxerror in INSERT INTO statement error

Joe
Hello All,

I am trying to insert a record in the MS Access DB and for some reason I cannot get rid of error message,

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

And the line it shows in red is

cmd.ExecuteNonQuery()

I have pasted the entire code here. Can someone please give me some clue as what could be wrong. The SQL string looks fine because I pasted the resulting SQL in to MS Access. When I ran the Insert query, it properly added the record in the Access DB.

Thanks,

Joe

<%@ Page Language="VB" Debug="true" ContentType="text/html" ResponseEncoding="iso-8859-1" %>
<%@ Import Namespace="System.Data.OleDb" %>
<%@ Import Namespace="System.Data" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<%
'Open up a connection to Access database
'Using a DSN connection.
Dim bolfFound, strUsername, bolAlreadyExists
Dim objConn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; data source='E:/Inetpub/databases/investors.mdb'")
objConn.Open()

'check state
If Session("strAdmin") <> "test" Then
objConn.Close()
objConn = Nothing
Response.Write("<A HREF=index.aspx'>")
Response.Write("Sorry, looks like your session timed out, please login again.")
Response.Write("</A>")
Response.End()
End If

bolAlreadyExists = False

Dim objDataReader as OledbDataReader
Dim objCommand as New OledbCommand("Select * From Results", objConn)
objDataReader = objCommand.ExecuteReader()

Do While Not (objDataReader.Read()= False OR bolAlreadyExists)
If (StrComp(objDataReader("Email"), Request.Form("Email"), vbTextCompare) = 0) Then
Response.Redirect("record_exists.aspx")
bolAlreadyExists = True
End If
Loop

objDataReader.Close()

If Not bolAlreadyExists Then

Dim Email, passwd, first_name, last_name, company, street_address, address2, city, prov, country, postal, phone, mobilePhone, AddDate,Investor, RemoteIP
Email = Request.Form("Email")
passwd = Request.Form("password")
first_name = Request.Form("first_name")
last_name = Request.Form("last_name")
company = Request.Form("company")
street_address = Request.Form("street_address")
address2 = Request.Form("address2")
city = Request.Form("city")
prov = Request.Form("state")
country = Request.Form("country")
postal = Request.Form("postal")
phone = Request.Form("phone")
mobilePhone = Request.Form("mobile")
AddDate = Now
Inv = "Yes"
RemoteIP = Request.ServerVariables("REMOTE_ADDR")

Dim MySQL as String

MySQL = "INSERT INTO Results(email, password, first_name, last_name, company, street_address, address2, city, state, country, postal, phone, mobile, AddDate, Inv, RemoteIP)" & _
" VALUES('" & Email & "', '" & passwd & "', '" & first_name & "', '" & last_name & "', '" & company & "', '" & street_address & "', '" & address2 & "', '" & city & "', '" & prov & "', '" & country & "', '" & postal & "', '" & phone & "', '" & mobilePhone & "', '" & AddDate & "', '" & Investor & "', '" & RemoteIP & "')"

Dim cmd as New OleDBCommand (MySQL, objConn)

cmd.ExecuteNonQuery ()
End if

objConn = Nothing
objConn.Close()

%>
___
Newsgroups brought to you courtesy of www.dotnetjohn.com
Nov 20 '05 #1
1 5380
Just a first glance - you'll need to add [ and ] to the following fields;

MySQL = "INSERT INTO Results(email, [password], first_name, last_name,
company, street_address, address2, city, state, country, postal, phone,
mobile, [AddDate], Inv, [RemoteIP])" & _
" VALUES('" & Email & "', '" & passwd & "', '" & first_name & "', '" &
last_name & "', '" & company & "', '" & street_address & "', '" & address2 &
"', '" & city & "', '" & prov & "', '" & country & "', '" & postal & "', '"
& phone & "', '" & mobilePhone & "', '" & AddDate & "', '" & Investor & "',
'" & RemoteIP & "')"

Also, to avoid date/time conflict errors and formatting issues, I suggest
you change the last line to;

& "', '" & mobilePhone & "', Now, '" & Investor & "', '" & RemoteIP & "')"

Hope this gets you on the right track - Access can be a stress tester...!!
_________________________________
The Grim Reaper

"Joe" <Jo*@joe.com> wrote in message
news:OB****************@TK2MSFTNGP10.phx.gbl...
Hello All,

I am trying to insert a record in the MS Access DB and for some reason I cannot get rid of error message,
System.Data.OleDb.OleDbException: Syntax error in INSERT INTO statement.

And the line it shows in red is

cmd.ExecuteNonQuery()

I have pasted the entire code here. Can someone please give me some clue as what could be wrong. The SQL string looks fine because I pasted the
resulting SQL in to MS Access. When I ran the Insert query, it properly
added the record in the Access DB.
Thanks,

Joe

<%@ Page Language="VB" Debug="true" ContentType="text/html" ResponseEncoding="iso-8859-1" %> <%@ Import Namespace="System.Data.OleDb" %>
<%@ Import Namespace="System.Data" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<%
'Open up a connection to Access database
'Using a DSN connection.
Dim bolfFound, strUsername, bolAlreadyExists
Dim objConn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; data source='E:/Inetpub/databases/investors.mdb'") objConn.Open()

'check state
If Session("strAdmin") <> "test" Then
objConn.Close()
objConn = Nothing
Response.Write("<A HREF=index.aspx'>")
Response.Write("Sorry, looks like your session timed out, please login again.") Response.Write("</A>")
Response.End()
End If

bolAlreadyExists = False

Dim objDataReader as OledbDataReader
Dim objCommand as New OledbCommand("Select * From Results", objConn)
objDataReader = objCommand.ExecuteReader()

Do While Not (objDataReader.Read()= False OR bolAlreadyExists)
If (StrComp(objDataReader("Email"), Request.Form("Email"), vbTextCompare) = 0) Then Response.Redirect("record_exists.aspx")
bolAlreadyExists = True
End If
Loop

objDataReader.Close()

If Not bolAlreadyExists Then

Dim Email, passwd, first_name, last_name, company, street_address, address2, city, prov, country, postal, phone, mobilePhone, AddDate,Investor,
RemoteIP Email = Request.Form("Email")
passwd = Request.Form("password")
first_name = Request.Form("first_name")
last_name = Request.Form("last_name")
company = Request.Form("company")
street_address = Request.Form("street_address")
address2 = Request.Form("address2")
city = Request.Form("city")
prov = Request.Form("state")
country = Request.Form("country")
postal = Request.Form("postal")
phone = Request.Form("phone")
mobilePhone = Request.Form("mobile")
AddDate = Now
Inv = "Yes"
RemoteIP = Request.ServerVariables("REMOTE_ADDR")

Dim MySQL as String

MySQL = "INSERT INTO Results(email, password, first_name, last_name, company, street_address, address2, city, state, country, postal, phone,
mobile, AddDate, Inv, RemoteIP)" & _ " VALUES('" & Email & "', '" & passwd & "', '" & first_name & "', '" & last_name & "', '" & company & "', '" & street_address & "', '" & address2 &
"', '" & city & "', '" & prov & "', '" & country & "', '" & postal & "', '"
& phone & "', '" & mobilePhone & "', '" & AddDate & "', '" & Investor & "',
'" & RemoteIP & "')"
Dim cmd as New OleDBCommand (MySQL, objConn)

cmd.ExecuteNonQuery ()
End if

objConn = Nothing
objConn.Close()

%>
___
Newsgroups brought to you courtesy of www.dotnetjohn.com

Nov 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: G.Esmeijer | last post by:
Friends, The following code works fin. BUT... after a >> couple times<< this code is used is a class it comes with an error saying unhandled System.Data.OleDb.OleDbException' occurred in...
2
by: Brian Basquille | last post by:
Apologies... was meant to sent this to ASP Newsgroup "Brian Basquille" <replytogroup@please.com> wrote in message news:OqzVTNWEFHA.3244@TK2MSFTNGP15.phx.gbl... > Hello all. > > Just a quick...
3
by: Mazer | last post by:
Hi! I have a problem with my code. I have a access database that I fill a my dataset with. Then I add new row to the dataset and save the changes back to the access database. When doing this I...
1
by: T8 | last post by:
I have a asp.net (framework 1.1) site interfacing against SQL 2000. It runs like a charm 99% of the time but once in a while I get the following "unspecified error". Sometimes it would resolve by...
2
by: Joe | last post by:
Hello All, I am trying to insert a record in the MS Access DB and for some reason I cannot get rid of error message, System.Data.OleDb.OleDbException: Syntax error in INSERT INTO statement. ...
0
by: NicK chlam via DotNetMonster.com | last post by:
this is the error i get System.Data.OleDb.OleDbException: Syntax error in INSERT INTO statement. at System.Data.Common.DbDataAdapter.Update(DataRow dataRows, DataTableMapping tableMapping) at...
1
by: smtwtfs007 | last post by:
I have an ASP.NET website. I'm trying to connect to a Foxpro database (ADO.NET) with the following connect string: txtConnectionStr.Text = "\\soya4042\Qd\LM\LMS\Data" Dim strFoxProDirectory As...
5
by: beenanair11 | last post by:
Hi friends, Im getting an error,in a particular line System.Data.OleDb.OleDbException: Incorrect syntax near the keyword 'DEFAULT'. at System.Data.OleDb.OleDbDataReader.ProcessResults(Int32 hr)...
2
by: gabielmatos | last post by:
this is my query; string NPI = fields.GetValue(0).ToString(); string EntiType = fields.GetValue(1).ToString(); string ProvLastNameLegal = ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.