Updating a record

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Swizylstik
    New Member
    • Sep 2006
    • 12

    Updating a record

    This should be easy right? Using this tutorial as a guide [HTML]http://www.w3schools.c om/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.o rg/RTape/test_shows_disp lay.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.o rg/RTape/test_shows_disp lay.txt[/HTML]
    and
    [HTML]http://www.simplymad.o rg/RTape/x_demoupdate.tx t[/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!
  • jhardman
    Recognized Expert Specialist
    • Jan 2007
    • 3405

    #2
    The first page looks good. In the second page you forgot to open the recordset:
    [code=asp]set rs=Server.Creat eObject("ADODB. Recordset")
    sSQL = "SELECT * FROM shows WHERE EventID='" & cid & "'"
    rs.open sSQL, db[/code]
    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: [code=asp]sql = "SELECT * FROM shows WHERE EventID='" & cid & "'"
    rs.open sql, db
    for each x in rs.fields
    if x.name="EventId " then
    'no change needed
    else
    rs(x) = request(x)
    end if
    next
    rs.update [/code] Let me know if this helps.

    Jared

    Comment

    • ilearneditonline
      Recognized Expert New Member
      • Jul 2007
      • 130

      #3
      Originally posted by jhardman
      [code=asp]sql = "SELECT * FROM shows WHERE EventID='" & cid & "'"
      [/code]
      Also, depending on the database, this query would not work if the eventid is a numeric value. In that case it would be
      [code=asp]sql="SELECT * FROM shows WHERE EventID=" & cid[/code]

      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.

      Comment

      • markrawlingson
        Recognized Expert Contributor
        • Aug 2007
        • 346

        #4
        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.

        Comment

        • syamas
          New Member
          • Sep 2007
          • 10

          #5
          Originally posted by jhardman
          The first page looks good. In the second page you forgot to open the recordset:
          [code=asp]set rs=Server.Creat eObject("ADODB. Recordset")
          sSQL = "SELECT * FROM shows WHERE EventID='" & cid & "'"
          rs.open sSQL, db[/code]
          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: [code=asp]sql = "SELECT * FROM shows WHERE EventID='" & cid & "'"
          rs.open sql, db
          for each x in rs.fields
          if x.name="EventId " then
          'no change needed
          else
          rs(x) = request(x)
          end if
          next
          rs.update [/code] Let me know if this helps.

          Jared
          I think the below changes
          set cn = Server.CreateOb ject("ADODB.Con nection")
          cn.open "provider=MICRO SOFT.JET.OLEDB. 4.0;DATA SOURCE=" & Server.MapPath( "\dbname.md b")
          rs.open sql, db, adopendynamic,a dlockoptimistic

          [removed signature. Sig is not allowed in technical posts]
          Last edited by jhardman; Sep 6 '07, 05:28 AM. Reason: remove signature

          Comment

          • Swizylstik
            New Member
            • Sep 2006
            • 12

            #6
            Thanks so much for your help with this!

            Comment

            Working...