|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
||||
|
||||
|
Insert Syntax Error
I'm getting Syntax error in INSERT INTO statement. for this code
Code:
Dim sNow
sNow = #1/12/2003 12:00 PM#
sQuery = "insert into members (stime, name, password, email, level) values " _
& "(" & sNow & ", '" & sName & "', '" & sPasswd & "', '" & sEmail & "', 0)"
stime is datetime name is varchar passwd is varchar email is varchar an level is int I'm using the 3.51 jet provider I've tried this many different ways an I'm not getting anywhere does anyone see my error?
__________________
Tewl Last edited by Tewl : July 13th, 2003 at 10:47 AM. |
|
#2
|
|||
|
|||
|
With Access databases, you need to use # as a delimiter around dates, not '
|
|
#3
|
||||
|
||||
|
I kno that. I have even tried this
Code:
insert into members (name, password, email, level) values ('Nickname', 'password', 'auser@hotmail.com', 0)
An I'm still getting a insert error Last edited by Tewl : July 12th, 2003 at 10:37 PM. |
|
#4
|
|||
|
|||
|
Password is a reserved word. Try
Code:
insert into members (name, [password], email, level) values ('Nickname', 'password', 'auser@hotmail.com', 0)
|
|
#5
|
||||
|
||||
|
No luck with that either. I even renamed the field to passwd an name to uname and still get the syntax error
Here is what I have at the moment Code:
Public Function AddMember(sName, sPasswd, sEmail)
On Error Resume Next
Dim sAddMember, sQuery
sAddMember = "MemberAdded"
adoCon.ConnectionString = dbProvider
adoCon.Open
' check if user already exists
sQuery = "select Count(*) from members where members.uname='" & sName & "'"
adoRS.Open sQuery, adoCon, adOpenKeySet, adLockOptimistic
If adoRS(0) <> 0 Then
sAddMember = "MemberAlreadyExists"
End If
adoRS.Close
' check if email already exists
sQuery = "select Count(*) from members where members.email='" & sEmail & "'"
adoRS.Open sQuery, adoCon, adOpenKeySet, adLockOptimistic
If adoRS(0) <> 0 Then
sAddMember = "EmailAlreadyExists"
End If
adoRS.Close
If sAddMember = "MemberAdded" Then
sQuery = "insert into members (uname, passwd, email, level) values ('" & sName & "', '" & sPasswd & "', '" & sEmail & "', 0)"
adoRS.Open sQuery, adoCon, adOpenKeySet, adLockOptimistic
End If
If Err.Number <> 0 Then
response.write "Error occured while adding user to database.<br>Error #" & Err.Number & "<br>Description: " & Err.Description & "<br>"
End If
adoCon.Close
AddMember = sAddMember
End Function
Last edited by Tewl : July 13th, 2003 at 10:50 AM. |
|
#6
|
|||
|
|||
|
Try taking out the on error resume next, maybe you're getting some error higher up in your code that's being hidden.
|
|
#7
|
||||
|
||||
|
I've tried that too. I can run it without the insert an it works fine but when I try the insert it gives me an error
|
|
#8
|
|||
|
|||
|
Maybe there is something you need to do if you use a recordset to perform an insert statement. Typically if you have an open recordset you'll use .addnew
I usually do a con.execute "INSERT INTO table (col1) VALUES ('val1')" to do an insert instead of passing the sql to a recordset. You could put a response.write sQuery just above the actual execution point and see just what the sql string looks like. Post it here if you have questions. |
|
#9
|
|||
|
|||
|
try this
store the value of level into a variable and then try to store that variable into the table maybe it is not storing the value 0 directly it's a wild guess but try it
__________________
Rahul Small things lead to perfection and perfection is not a small thing. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ASP Programming > Insert Syntax Error |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|