472,358 Members | 1,696 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,358 software developers and data experts.

Updating a record

This should be easy right? Using this tutorial as a guide [HTML]http://www.w3schools.com/ado/ado_update.asp[/HTML] and I still can't get it to work.

Here is a sample of what I have and what the outcome is: [HTML]http://www.simplymad.org/RTape/test_shows_display.asp[/HTML]

I've saved the two asp files as txt files so that you may see the code behind this mess I've made:

[HTML]http://www.simplymad.org/RTape/test_shows_display.txt[/HTML]
and
[HTML]http://www.simplymad.org/RTape/x_demoupdate.txt[/HTML]

Can anyone help me understand what I'm doing wrong here? And is there any online resource that will be more helpful than the page I mention above? This is newbie stuff and I'm still lost!

Thanks!
Sep 4 '07 #1
5 1132
jhardman
3,406 Expert 2GB
The first page looks good. In the second page you forgot to open the recordset:
Expand|Select|Wrap|Line Numbers
  1. set rs=Server.CreateObject("ADODB.Recordset")
  2.      sSQL = "SELECT * FROM shows WHERE EventID='" & cid & "'"
  3. rs.open sSQL, db
It might also be a good idea to make the eventId different, perhaps readonly or hidden so the user can't change this on accident, then on the update section you can simplify to this:
Expand|Select|Wrap|Line Numbers
  1. sql = "SELECT * FROM shows WHERE EventID='" & cid & "'"
  2. rs.open sql, db
  3. for each x in rs.fields
  4.    if x.name="EventId" then
  5.       'no change needed
  6.    else
  7.       rs(x) = request(x)
  8.    end if
  9. next
  10. rs.update 
Let me know if this helps.

Jared
Sep 5 '07 #2
ilearneditonline
130 Expert 100+
Expand|Select|Wrap|Line Numbers
  1. sql = "SELECT * FROM shows WHERE EventID='" & cid & "'"
  2.  
Also, depending on the database, this query would not work if the eventid is a numeric value. In that case it would be
Expand|Select|Wrap|Line Numbers
  1. sql="SELECT * FROM shows WHERE EventID=" & cid
Also, when I am having problems like this, I would print out the SQL rather than execute it. Then I would run the output directly against the database with whatever interface is available. MS SQL i would use query analyzer. This way you can see if you are getting the expected results.
Sep 6 '07 #3
markrawlingson
346 Expert 100+
If the "EventID" is a unique identifier in your table - Just set it up as an autonumber/primary key in the database. It will automatically be read-only and it counts/updates by itself, so you don't have to.
Sep 6 '07 #4
syamas
10
The first page looks good. In the second page you forgot to open the recordset:
Expand|Select|Wrap|Line Numbers
  1. set rs=Server.CreateObject("ADODB.Recordset")
  2.      sSQL = "SELECT * FROM shows WHERE EventID='" & cid & "'"
  3. rs.open sSQL, db
It might also be a good idea to make the eventId different, perhaps readonly or hidden so the user can't change this on accident, then on the update section you can simplify to this:
Expand|Select|Wrap|Line Numbers
  1. sql = "SELECT * FROM shows WHERE EventID='" & cid & "'"
  2. rs.open sql, db
  3. for each x in rs.fields
  4.    if x.name="EventId" then
  5.       'no change needed
  6.    else
  7.       rs(x) = request(x)
  8.    end if
  9. next
  10. rs.update 
Let me know if this helps.

Jared
I think the below changes
set cn = Server.CreateObject("ADODB.Connection")
cn.open "provider=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE=" & Server.MapPath("\dbname.mdb")
rs.open sql, db, adopendynamic,adlockoptimistic

[removed signature. Sig is not allowed in technical posts]
Sep 6 '07 #5
Thanks so much for your help with this!
Sep 7 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: Jason | last post by:
Let's say I have an html form with 20 or 30 fields in it. The form submits the fields via POST to a php page which updates a table in a database with the $_POST vars. Which makes more sense? ...
3
by: MLH | last post by:
I have a form, bound to a query. Its RecordSource property is a query named frmEnterLienAmounts. The form has a few bound controls and some unbound controls. The unbound controls are calculated...
5
by: junglist | last post by:
Hi guys, I've been trying to implement an editable datagrid and i have been succesful up to the point where i can update my datagrid row by row. However what used to happen was that once i updated...
4
by: Winshent | last post by:
I am having problems with adding items to my shopping cart. The problem occures when adding items that already exists in the cart. When a user adds to cart, they are automatically redirected to...
4
by: aaronyoung | last post by:
I have created custom navigation buttons and Record Number indicators on several forms that are used to review and update records based on a query. My On Current event to update the "Record X of...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
1
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. header("Location:".$urlback); Is this the right layout the...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and credentials and received a successful connection...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
1
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.