Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Other Forums
 MS Access
 Syntax error in INSERT INTO

Author  Topic 

jrahma
Starting Member

16 Posts

Posted - 2003-02-13 : 16:20:15
I'm bevame mad with this now. It keeps showing this error when I try to insert a record using ASP+SQL to MS Access database:

Microsoft OLE DB Provider for ODBC Drivers (0x80040E14)
[Microsoft][ODBC Microsoft Access Driver] Syntax error in INSERT INTO statement.


my code is:


Session("news_photo") = Request.Form("txtPhoto")
Session("news_photo_title") = Request.Form("txtPhotoTitle")

Dim conn, rs, strSQL, strIP_Address, news_date

strIP_Address = Request.ServerVariables("REMOTE_ADDR")

news_date = Session("news_year") & "/" & Session("news_month") & "/" & Session("news_day")

news_date = CDate(news_date)

Set conn = Server.CreateObject("ADODB.Connection")

conn.CursorLocation = 3

conn.Open "b4all_news"

Set rs = Server.CreateObject("ADODB.Recordset")

Set rs = conn.Execute("SELECT COUNT(*) AS total_contacts FROM news WHERE title = '" & Session("news_title") & "'")

If rs("total_contacts") >= 1 Then
Session("error_message") = "Êã ÇáÚ辄 Úáì ÎÈÑ íÍãá äÝÓ ÇáÚäæÇä ¡ íÑÌì ÇáÊÃßÏ æÊÛííÑ ÇáÚäæÇä"
Response.Redirect "error.asp"
Else
strSQL = "INSERT INTO news (news_date, news_time, category, title, text, breaking, released, news_photo, photo_title, created_date, created_ip) Values ('" & news_date & "', '" & Time & "', '" & Session("news_category") & "', '" & Session("news_title") & "', '" & Session("news_text") & "', '" & Session("is_Breaking") & "', '" & Session("is_release") & "', '" & Session("news_photo") & "', '" & Session("news_photo_title") & "', '" & Now & "', '" & strIP_Address & "')"

Session("SQL") = strSQL

Set rs = conn.Execute(strSQL)

Set rs = Nothing
Set conn = Nothing
End If

Response.Redirect "index.asp"


jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2003-02-13 : 18:46:06
Dates needs to be surrounded by # in ms access, not by ' as in SQL server.

- Jeff
Go to Top of Page

LarsG
Constraint Violating Yak Guru

284 Posts

Posted - 2003-02-14 : 04:05:39
text is a reserved word in Access/Jet. The best thing is to rename the column or use [text].

Go to Top of Page
   

- Advertisement -