473,849 Members | 1,779 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Please help : System.Data.Ole Db.OleDbExcepti on: 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.Ole Db.OleDbExcepti on: Syntax error in INSERT INTO statement.

And the line it shows in red is

cmd.ExecuteNonQ uery()

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="te xt/html" ResponseEncodin g="iso-8859-1" %>
<%@ Import Namespace="Syst em.Data.OleDb" %>
<%@ Import Namespace="Syst em.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, bolAlreadyExist s
Dim objConn As New OleDbConnection ("Provider=Micr osoft.Jet.OLEDB .4.0;data source='E:/Inetpub/databases/investors.mdb'" )
objConn.Open()

'check state
If Session("strAdm in") <> "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

bolAlreadyExist s = False

Dim objDataReader as OledbDataReader
Dim objCommand as New OledbCommand("S elect * From Results", objConn)
objDataReader = objCommand.Exec uteReader()

Do While Not (objDataReader. Read()= False OR bolAlreadyExist s)
If (StrComp(objDat aReader("Email" ), Request.Form("E mail"), vbTextCompare) = 0) Then
Response.Redire ct("record_exis ts.aspx")
bolAlreadyExist s = True
End If
Loop

objDataReader.C lose()

If Not bolAlreadyExist s Then

Dim Email, passwd, first_name, last_name, company, street_address, address2, city, prov, country, postal, phone, mobilePhone, AddDate,Investo r, RemoteIP
Email = Request.Form("E mail")
passwd = Request.Form("p assword")
first_name = Request.Form("f irst_name")
last_name = Request.Form("l ast_name")
company = Request.Form("c ompany")
street_address = Request.Form("s treet_address")
address2 = Request.Form("a ddress2")
city = Request.Form("c ity")
prov = Request.Form("s tate")
country = Request.Form("c ountry")
postal = Request.Form("p ostal")
phone = Request.Form("p hone")
mobilePhone = Request.Form("m obile")
AddDate = Now
Inv = "Yes"
RemoteIP = Request.ServerV ariables("REMOT E_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.ExecuteNonQ uery ()
End if

objConn = Nothing
objConn.Close()

%>
___
Newsgroups brought to you courtesy of www.dotnetjohn.com
Nov 20 '05 #1
1 5433
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******** ********@TK2MSF TNGP10.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.Ole Db.OleDbExcepti on: Syntax error in INSERT INTO statement.

And the line it shows in red is

cmd.ExecuteNonQ uery()

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="te xt/html" ResponseEncodin g="iso-8859-1" %> <%@ Import Namespace="Syst em.Data.OleDb" %>
<%@ Import Namespace="Syst em.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, bolAlreadyExist s
Dim objConn As New OleDbConnection ("Provider=Micr osoft.Jet.OLEDB .4.0;data source='E:/Inetpub/databases/investors.mdb'" ) objConn.Open()

'check state
If Session("strAdm in") <> "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

bolAlreadyExist s = False

Dim objDataReader as OledbDataReader
Dim objCommand as New OledbCommand("S elect * From Results", objConn)
objDataReader = objCommand.Exec uteReader()

Do While Not (objDataReader. Read()= False OR bolAlreadyExist s)
If (StrComp(objDat aReader("Email" ), Request.Form("E mail"), vbTextCompare) = 0) Then Response.Redire ct("record_exis ts.aspx")
bolAlreadyExist s = True
End If
Loop

objDataReader.C lose()

If Not bolAlreadyExist s Then

Dim Email, passwd, first_name, last_name, company, street_address, address2, city, prov, country, postal, phone, mobilePhone, AddDate,Investo r,
RemoteIP Email = Request.Form("E mail")
passwd = Request.Form("p assword")
first_name = Request.Form("f irst_name")
last_name = Request.Form("l ast_name")
company = Request.Form("c ompany")
street_address = Request.Form("s treet_address")
address2 = Request.Form("a ddress2")
city = Request.Form("c ity")
prov = Request.Form("s tate")
country = Request.Form("c ountry")
postal = Request.Form("p ostal")
phone = Request.Form("p hone")
mobilePhone = Request.Form("m obile")
AddDate = Now
Inv = "Yes"
RemoteIP = Request.ServerV ariables("REMOT E_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.ExecuteNonQ uery ()
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
5426
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 system.data.dll Any suggestions what could be wrong.
2
1295
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 question. > > Can anyone see what's wrong with this ASP page? Am creating it in > WebMatrix and it's giving me the error: "System.Data.OleDb.OleDbException:
3
1220
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 get an exception saying: System.Data.OleDb.OleDbException: Syntax error in Insert into statement. Would be thankful if some guru could take a look at it....
1
6906
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 itself (asp.net recycled?); it also can be solved by restarting IIS. Any ideas what cause(s) this to happen? System.Data.OleDb.OleDbException: Unspecified error at System.Data.OleDb.OleDbDataReader.ProcessResults(Int32 hr) at...
2
2854
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. And the line it shows in red is cmd.ExecuteNonQuery()
0
5686
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 System.Data.Common.DbDataAdapter.Update(DataSet dataSet, String srcTable) at System.Data.Common.DbDataAdapter.Update(DataSet dataSet) at TryThis.Form1.save() in C:\Documents and Settings\Nick\My Documents\...
1
1859
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 String = txtConnectionStr.Text Dim strConnection As String = "User ID=;DSN=;Cache Authentication=False;Data Source='" & _ Trim(strFoxProDirectory) & "'" & _
5
4745
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) at System.Data.OleDb.OleDbDataReader.NextResult() at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method) at System.Data.OleDb.OleDbCommand.ExecuteReader(CommandBehavior behavior) at...
2
1805
by: gabielmatos | last post by:
this is my query; string NPI = fields.GetValue(0).ToString(); string EntiType = fields.GetValue(1).ToString(); string ProvLastNameLegal = fields.GetValue(5).ToString(); string ProvFirsName = fields.GetValue(6).ToString(); string ProvMiddName = fields.GetValue(7).ToString(); string PromNamePref = fields.GetValue(8).ToString(); ...
0
9893
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9738
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11005
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10665
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10723
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9501
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7070
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5735
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
4139
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.