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
 Insert into Statement syntax error

Author  Topic 

slapmonkay
Starting Member

2 Posts

Posted - 2006-02-18 : 16:50:05
[code]<%
' Declaring variables
Dim data_source, con, sql_insertSeason, Game, Season, Size

' A Function to check if some field entered by user is empty
Function ChkString(string)
If string = "" Then string = " "
ChkString = Replace(string, "'", "''")
End Function

' Receiving values from Form
Game = ChkString(Request.Form("Game"))
Season = ChkString(Request.Form("Season"))
Size = ChkString(Request.Form("Size"))


data_source = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & _
Server.MapPath("..\DB\TCSLPlayoffs.mdb")
sql_insertSeason = "insert into GameSize (Game, Season, Size) values ('" & _
Game & "', '" & Season &"', '" & Size &"')"


' Creating Connection Object and opening the database
Set con = Server.CreateObject("ADODB.Connection")
con.Open data_source
con.Execute sql_insertSeason
' Done. Close the connection
con.Close
Set con = Nothing
Response.Redirect "AddSeasonComplete.asp"
%>
[/code]

Causes the following error. does anyone know what i did incorrect in the statment. Thanks.


[code]Microsoft JET Database Engine error '80040e14'

Syntax error in INSERT INTO statement.

/slapmonkay/TCSLPlayoffs/Admin/AddSeasonDB.asp, line 34 [/code]

Kristen
Test

22859 Posts

Posted - 2006-02-19 : 04:15:44
Maybe Game, Season or Size has a single quote in it?

Try putting

Response.Write("SQL Command:" & sql_insertSeason)
Response.End

in place of just above

con.Execute sql_insertSeason

so you can see what the actual generated SQL command is

Kristen
Go to Top of Page
   

- Advertisement -