Jump to content
Sign in to follow this  
Mixaalser684

I can't get really simple update to work

Recommended Posts

I have a database with three columns:

intKorisnikID (Autonumber) - UserIDtxtIme (txt) - User NametxtPrezime (txt) - User Surname

On the edit.asp page I'm passing the user ID via Request.QueryString("id"), and in the form on that page I want to b able to edit the name or surname of the selected user (from the index.asp page)Here is the edit.asp code:

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>Admin - Edit</title></head><body><p><a href="index.asp">View Users</a></p><%Dim DBSet DB = Server.CreateObject("ADODB.Connection") DB.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="&Server.MapPath("db/dbKorisnici.mdb")&";"Dim RSSet RS = Server.CreateObject("ADODB.Recordset")Dim SQLSQL = "SELECT * FROM tblKorisnici ORDER BY txtPrezime ASC;"RS.Open SQL, DB, 3, 3Dim updateSQLupdateSQL = "UPDATE tblKorisnici SET txtIme = '" & Request.Form("txtIme") & "' WHERE intKorisnikID = '" & Request.Form("txtID") & "' ;"DB.Execute updateSQL%><form action="edit.asp" method="post"><input name="txtID" type="hidden" value="<%= Request.QueryString("id") %>" /><input name="txtIme" type="text" value="<%=(RS.Fields.Item("txtIme").Value)%> "/><input name="txtPrezime" type="text" value="<%=(RS.Fields.Item("txtPrezime").Value)%>" /><input name="Submit" type="submit" value="Edit" /></form><%RS.CloseSet RS = NothingDB.CloseSet DB = Nothing%></body></html>

On Line 29. which is DB.Execute updateSQL I'm getting Data type mismatch in criteria expression. I know it has something to do with the WHERE intKorisnikID = '" & Request.Form("txtID") & "' SQL clause, but I don't know how to make this work.If I put a number let say 14 instead of '" & Request.Form("txtID") & "' everything is working as it should the only problem is that I'm updating the same record (14th )each time.What do I need to put in order to be able to update the selected user (passed ID from the Request.QueryString("id")?Thanx.

Share this post


Link to post
Share on other sites

Have you tried commenting out the line that executes the SQL and add in a test line that out puts the SQL to the screen so that you can check to see if it's valid.

response.write updateSQL

For testing I sometime even manually type in the SQL for the update to test it just like the SQL that you have defined.I find that once you have identified the SQL problem you can then amend the code building up the SQL statement.

Share this post


Link to post
Share on other sites
Have you tried commenting out the line that executes the SQL and add in a test line that out puts the SQL to the screen so that you can check to see if it's valid.
response.write updateSQL

For testing I sometime even manually type in the SQL for the update to test it just like the SQL that you have defined.I find that once you have identified the SQL problem you can then amend the code building up the SQL statement.

That was exactly what I did to try to solve al my problems. I've solved this one. Thanx

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...