Home | Advertising Info39 USERS CURRENTLY ONLINE   
PowerASP
   Site Search Contact Us Wednesday, January 15, 2025  

  Active InfoActive Info  Display List of Info MembersMemberlist  Search The InfoSearch  HelpHelp
  RegisterRegister  LoginLogin
Classic ASP - Database Issues
 PowerASP Code Help Area : Classic ASP - Database Issues
Subject Info: Updating a record A d d  -  P o s tAdd P o s t
Author
Message << Prev Info | Next Info >>
katlees
Newbie
Newbie


Joined: July/09/2004
Location: United States
Online Status: Offline
Info: 2
Added: July/09/2004 at 12:53pm | IP Logged Quote katlees

  I have a site where it displays certain records on one page. If the admin wants to update a record, they enter the ID# of the record and click on Get Record. It pulls up the record information, then a form to enter updated info. I can't get the form to update.

I open the recordset and view it based on the number entered on the previous screen with this code...

<%
   Dim MyConn, RS, word1
word1 = Request("word1")
   Set MyConn = Server.CreateObject("ADODB.Connection")
   Set RS = Server.CreateObject("ADODB.RecordSet")
   MyConn.Mode = adModeReadWrite
   MyConn.Open ("PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" + Server.MapPath("geagents.mdb"))
     
   RS.Open "SELECT * FROM agents where "&_
"id like '%" & word1 & "%';",MyConn

%>

Here is the update code...
<%
Dim RID
RID = Request.Form("RID")
sql = "UPDATE agents SET name = '" & request.form("name") & "', address = '" & request.form("address") & "', city = '" & request.form("city") & "', state = '" & request.form("state") & "', zip = '" & request.form("zip") & "', compperson = '" & request.form("compperson") & "', compemail = '" & request.form("compemail") & "', status = '" & request.form("status") & "', appdate = '" & request.form("appdate") & "', notes = '" & request.form("notes") & "' where "&_
"id like '%" & RID & "%';"

MyConn.execute(sql)
MyConn.Close
%>

Please help!!


Edited by cwilliams on July/09/2004 at 6:24pm
Back to Top View katlees's Profile Search for other info by katlees
 
cwilliams
Admin Group
Admin Group
Avatar

Joined: April/26/2004
Location: United States
Online Status: Offline
Info: 137
Added: July/09/2004 at 6:30pm | IP Logged Quote cwilliams

If ID is a number field in the the database you can not use LIKE to specify it.

You do something like this instead.

where "&_
(ID = " & RID & ")"

Like is just for string searches

Ultimately your also going to want to check each one of the values posted and make sure they have no apostraphes.. if the do you need to replace that with 2 apostrophes.. otherwise you will break the SQL string and get an error.

Like so

name = replace(request.form("name"),"'","''")

http://www.aspfaq.com/show.asp?id=2035


Other than that your code looks ok. There may be other problems but I dont see them with a quick look..



Edited by cwilliams on July/09/2004 at 6:31pm


__________________


Chris Williams
http://www.PowerASP.com
Back to Top View cwilliams's Profile Search for other info by cwilliams
 
katlees
Newbie
Newbie


Joined: July/09/2004
Location: United States
Online Status: Offline
Info: 2
Added: July/12/2004 at 1:23pm | IP Logged Quote katlees

Thanks for the message but it still doesn't work. I have the code set at this..

 

<%
Dim RID
RID = Request.Form("RID")
sql = "UPDATE agents SET name = '" & request.form("name") & "', address = '" & request.form("address") & "', city = '" & request.form("city") & "', state = '" & request.form("state") & "', zip = '" & request.form("zip") & "', compperson = '" & request.form("compperson")  & "', compemail = '" & request.form("compemail")  & "', status = '" & request.form("status")  & "', appdate = '" & request.form("appdate")  & "', notes = '" & request.form("notes")
where "&_
(ID = " & RID & ")"

 


MyConn.execute(sql)
MyConn.Close
%>

 

And I get this error

 

Microsoft VBScript runtime error '800a000d'

Type mismatch: 'where'

/ge/edit.asp, line 155

Back to Top View katlees's Profile Search for other info by katlees
 
cwilliams
Admin Group
Admin Group
Avatar

Joined: April/26/2004
Location: United States
Online Status: Offline
Info: 137
Added: July/12/2004 at 6:28pm | IP Logged Quote cwilliams

That just means there is an error in your SQL string somewhere.
Your going to have to find it..

My guess is your missing the ASP continutation character at the end of the line before the word  where

Everything has to be perfect when generating a string like that.

I would also recommened doing this which each variable to make the SQL string shorter and easier to read

name = request("name")
UPDATE agents SET name = '" & name & "'

As a matter of fact I would take all the variables passed to that page and set them at the top before the SQL string gets generated. That way you can also do a replace on them and take care of the potential apostrophe issue at the same time

You also should use more decriptive variable names...  "name" is not really a good name for a field or a variable



Edited by cwilliams on July/12/2004 at 6:30pm


__________________


Chris Williams
http://www.PowerASP.com
Back to Top View cwilliams's Profile Search for other info by cwilliams
 

If you wish to make a comment to this info you must first login
If you are not already registered you must first register

  A d d  -  P o s tAdd P o s t
Printable version Printable version

Info Jump
You cannot add new info in this area
You cannot add to info in this area
You cannot delete your info in this area
You cannot edit your info in this area
You cannot create polls in this area
You cannot vote in polls in this area

   Active Server Pages Rule The World
Contact Us  
All artwork, design & content contained in this site are Copyright © 1998 - 2025 PowerASP.com and Christopher J. Williams
Banner ads ,other site logos, etc are copyright of their respective companies.
STATS Unless otherwise noted - All Rights Reserved.

Active Server Pages ASP ASP.NET .aspx .ascx Web HTML Developer Internet Microsoft Web Services Visual Studio .NET CJWSoft ASPProtect ASPBanner ASPClassifieds www.aspprotect.com, www.cjwsoft.com,www.aspclassifieds.com,www.aspphotogallery.com