PDA

View Full Version : Insert Validation Error


dude9er
07-31-2008, 08:45 PM
I am trying to insert form data into an access DB table called users. I am trying to validate if an id already exists, if it does the insert is denied. I am getting this error

"Data type mismatch in criteria expression."

line 32 is the error and reads


rs.Open "SELECT id FROM users WHERE id='" & id & "'", conn


from this insert code:


<%
' Declaring variables
Dim name, id, email, country, comments, data_source, con, sql_insert

' A Function to check if some field entered by user is empty
' Receiving values from Form
name = Request.Form("name")
email = Request.Form("email")
country = Request.Form("country")
comments = Request.Form("comments")
id = Request.Form("id")

data_source = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & _
Server.MapPath("/access_db/form.mdb")

SET conn = Server.CreateObject("ADODB.Connection")
conn.OPEN data_source
Set rs = Server.CreateObject("ADODB.RecordSet")

rs.Open "SELECT id FROM users WHERE id='" & id & "'", conn

if rs.EOF Then
sql2= "INSERT INTO users(id, name, email, country, comments) VALUES ('" & id & "'," & _
" '" & name & "', '" & email & "', '" & country & "', '" & comments & "')"
Conn.Execute(SQL2)
Response.Write "Inserted sucessfully."
Else
Response.Write "'" & id & "' is already there in database."
End if
rs.Close

%>


I can't figure this out. HELP PLEASE!!!

dude9er
07-31-2008, 09:01 PM
SOLVED

rs.Open "SELECT id FROM users WHERE id=" & id, conn