473,418 Members | 1,715 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,418 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 1195
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.