Avatar of Justin Imes
Justin Imes
Flag for United States of America asked on

ASP SQL SYNTAX ERROR

I am trying to put together a simple web app for deleting and adding new posts.

I have a form setup on addnew.asp here is the form code
<form name="addnew" method="post" action="addcodage.asp">

addcodage.asp:

here is the ASP code where it breaks.
 <%  
frm_dbID = Request.Form("ID")
frm_dbDate = Request.Form("DATE")
frm_dbPosition = Request.Form("POSITION")
frm_dbDepartment = Request.Form("DEPARTMENT")
frm_dbDescription = Request.Form("DESCRIPTION")
frm_dbRate = Request.Form("RATE")
frm_dbvisible = Request.Form("VISIBLE")
frm_dbPTFT = Request.Form("PTFT")
frm_dbFile = Request.Form("File")

SQLText = "INSERT INTO Posting (ID, DATE, POSITION, DEPARTMENT, DESCRIPTION, RATE, VISIBLE, PTFT, File) VALUES (" & frm_dbID & "," & frm_dbDate & ",'"& frm_dbPosition & "','" & frm_dbDepartment & "','" & frm_dbDescription & "','" & frm_dbRate & "','"  & frm_dbvisible & "','"  & frm_dbPTFT & "','"  & frm_dbFile & "')"

SQLUser="Provider=SQLOLEDB.1;User ID=****;PASSWORD=****;Initial Catalog=Employment;Data Source=DCABSQL01c"
set recordset = server.createobject("adodb.recordset") <--------BREAKS ON THIS LINE
recordset.open SQLText, SQLUser, 3, 3
      
Response.write(SQLTEXT)

Response.write("<P> Post Successfully Added")

'Do while not Recordset.Eof
'Set Recordset = Nothing
%>

i know i'm doing something simple wrong, if i comment out set recordset and recordset.open everything works but it obviously doesn't insert it into the database.  any suggestions?
ASPSQL

Avatar of undefined
Last Comment
Justin Imes

8/22/2022 - Mon
dosth

<%
set conn=Server.CreateObject("ADODB.Connection")

SQLUser="Provider=SQLOLEDB.1;User ID=****;PASSWORD=****;Initial Catalog=Employment;Data Source=DCABSQL01c"

conn.Open SQLUser

set rs=Server.CreateObject("ADODB.recordset")
rs.Open SQLText, SQLUser
%>


_Stilgar_

What is the error you're getting?

Also, for editing, inserting or deleting a line you don't need a recordset, you'll only need it if you were trying to read data from the DB. Try creating a DB connection and executing the SQL sentence directly using it (DBConn.Execute strSQL).

Stilgar.
Justin Imes

ASKER
well I now added set conn=Server.CreateObject("ADODB.Connection") and the conn.open SQLUser
as suggested by dosth... that errored and gave me the same error... but if i comment out the recordset codage... it seems to work, but it doesn't insert it into SQL... but it doesn't error.

the error i was getting was

Microsoft OLE DB Provider for SQL Server error '80040e14'

Incorrect syntax near the keyword 'File'.

/employment/admin/addcodage.asp, line 57
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
Guy Hengel [angelIII / a3]

FILE is a reserved keyword in SQL:
SQLText = "INSERT INTO Posting (ID, DATE, POSITION, DEPARTMENT, DESCRIPTION, RATE, VISIBLE, PTFT, [File] )  ....

Open in new window

_Stilgar_

ID too. Just surround every table/field name with brackets or rename your table field names...
Justin Imes

ASKER
even if i delete the File variable and use the set conn, conn.open SQLUser, same result

it goes through and displays successful, but it doesn't actually insert it into SQL.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Guy Hengel [angelIII / a3]

>but it doesn't actually insert it into SQL.
then, you must be looking in another table/database than the insert runs into.
either the SQL works, or it errors out...

you might have a trigger on the table rolling the change back...
ASKER CERTIFIED SOLUTION
_Stilgar_

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Justin Imes

ASKER
Works... Thank You Stilgar.

wonder what the problem was.