Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Syntax error in INSERT INTO statement.

Status
Not open for further replies.

exodus300

Programmer
Mar 22, 2002
262
AU
What is so different about the following two queries, that the first one works OK and the second one generates the message,
Microsoft OLE DB Provider for ODBC Drivers error '80040e14'

[Microsoft][ODBC Microsoft Access Driver] Syntax error in INSERT INTO statement.

Query 1 (works):
Code:
INSERT INTO Users (UserName, Password, FirstName, LastName, Email, Location, TimesLoggedIn, LastLogin, IsAdmin) Values('a', 'a', 'a', 'a', 'a', 'a', '0', 'Never', False)

Query 2 (error):
Code:
INSERT INTO Messages (PostDate, PostTime, From, Subject, ReplyTo, MessageBody) Values('29/06/2002', '1:33:38 PM', 'Brendan', 'submit test', ' 2 ', 'Spectacularrrr')

Code generating Query 1:
Code:
		sqlQuery = "INSERT INTO Users (UserName, Password, FirstName, LastName, Email, Location, " &_
			"TimesLoggedIn, LastLogin, IsAdmin) Values('" & Request.Form("UserName") & "', '" &_
			Request.Form("Password") & "', '" & Request.Form("FirstName") & "', '" & Request.Form("LastName") &_
			"', '" & Request.Form("Email") & "', '" & Request.Form("Location") & "', '0', 'Never', " & AMU & ")"

Code generating Query 2:
Code:
	sqlQuery = _
		"INSERT INTO Messages (PostDate, PostTime, From, Subject, ReplyTo, MessageBody) " &_
		"Values(" &_
			"'" & Date & "', " &_
			"'" & Time & "', " &_
			"'" & Request.Form("Name") & "', " &_
			"'" & Request.Form("Subject") & "', " &_
			"'" & Request.Form("ReplyTo") & "', " &_
			"'" & Request.Form("MessageBody") & "')"
[pc3]
 
Have you checked all the datatypes of the database fields?

I notice you are inserting a '2' instead of a 2 without the quotes. You can't insert a '2' into a numeric field type, neither can you insert a 2 into a varchar/text field type.

Hope this helps.
 
I've tried it both ways, that doesn't seem to make any diffference. The first query has '0' in it and it works OK. The fields are all text, except for the one Number one (ReplyTo), and a Memo field (MessageBody). [pc3]
 
hi,
in ur query(error)
---
INSERT INTO Messages (PostDate, PostTime, From, Subject, ReplyTo, MessageBody) Values('29/06/2002', '1:33:38 PM', 'Brendan', 'submit test', ' 2 ', 'Spectacularrrr')


From is a key word...
rename the field in database & try..
hope that may work..
 
hi,
in ur query(error)
---
INSERT INTO Messages (PostDate, PostTime, From, Subject, ReplyTo, MessageBody) Values('29/06/2002', '1:33:38 PM', 'Brendan', 'submit test', ' 2 ', 'Spectacularrrr')


"From" is a key word... and ur having that as one of ur field in database..

rename the field in database & try..
hope this will work..
 
Hmm, I didn't think of that, thanks!

I've seen some things around saying if you want a keyword as a field name, you must put it in quotes (ie. "From"), I'll try that, but it would probably better just to rename it altogheter.

Thank you for your help! [pc3]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top