Results 1 to 11 of 11

Thread: Adding a record in an access database using ASP & ADO

  1. #1
    Guest
    Help! Please please help!!
    I'm trying to figure out how to add a record to a table in a database. I've got:
    Code:
    dim oRSu
    set oRSu = Server.CreateObject("ADODB.Recordset")
    oRSu.Open "users","DSN=fbquiz"
    oRSu.AddNew
     
    oRSu("Name") = sName
    oRSu("Address") = sAddress
    oRSu("Town") = sTown
    oRSu("County") = sCounty
    oRSu("Post_Code") = sPostCode
    oRSu("Country") = sCountry
    oRSu("EMail") = sEMail
    oRSu("User_Name") = sUsername
    oRSu("Password") = sPassword
     
    oRSu.Update
    set oRSu = Nothing
    but I keep getting "The operation requested by the application is not supported by the provider." on the "oRSu.AddNew" line.
    What am I doing wrong?

  2. #2
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    I always use SQL to interact with databases in ASP. I know that doesn't help, but maybe you should try it because I know it works
    Harry.

    "From one thing, know ten thousand things."

  3. #3
    Guest
    Go on then, Harry, what's the sequel code to do it?

  4. #4
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744

    Lightbulb

    It happens not because you open Table based recordset, but because you didn't specify the CursorType for your recordet. The default is adOpenForwardOnly, which is not updatable. If you want your recordset to be updatable, you have to open it as adOpenKeyset or adOpenDynamic. So your code should be like this:
    Code:
    <%
        Dim oRSu
        Set oRSu = Server.CreateObject("ADODB.Recordset")
        oRSu.Open "users","DSN=fbquiz", adOpenKeyset
        oRSu.AddNew
     
        oRSu("Name") = sName
        oRSu("Address") = sAddress
        oRSu("Town") = sTown
        oRSu("County") = sCounty
        oRSu("Post_Code") = sPostCode
        oRSu("Country") = sCountry
        oRSu("EMail") = sEMail
        oRSu("User_Name") = sUsername
        oRSu("Password") = sPassword
     
        oRSu.Update
        Set oRSu = Nothing
    %>

  5. #5
    Guest
    Ta Serge...but I was still getting some error about the currect recordset not supporting the addnew function.

    A collegue at work just sugested:
    Code:
    Set Conn=Server.CreateObject("ADODB.Connection")
    Conn.Open("DSN=fbquiz")
    Set oRSu=Server.CreateObject("ADODB.Recordset")
    oRSu.Open "users",Conn,3,3
    oRSu.Addnew
    	
    oRSu("Name") = sName
    oRSu("Address") = sAddress
    RSu("Town") = sTown
    oRSu("County") = sCounty
    oRSu("Post_Code") = sPostCode
    oRSu("Country") = sCountry
    oRSu("EMail") = sEMail
    oRSu("User_Name") = sUsername
    oRSu("Password") = sPassword
    	
    oRSu.Update
    set oRSu = Nothing
    set conn=nothing
    which seems to work ok now.

  6. #6
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744

    Lightbulb

    The reason for that is because VBScript didn't undertand adOpenKeyset constant, because you didn't reference ADO object library.

    In your code 3 means adOpenKeyset, in other words, adOpenKeyset constant has a value of 3.
    That's it.

  7. #7
    Guest
    LOL!! I've just been looking through the code and messin about and come to the same conclusion.

    If I use my collegue's code but with the constants instead of 3 it produces the same error as my code.

    So why does Visual Interdev suggest these constants if the ASP interpreter doesn't understand them? Mad that!!

    Anyway...works now and I'm back to using my original code...with ", 3, 3" tagged on the end of the open line.

    Thanks Serge.

  8. #8
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    You should have the file 'adovbs.inc' somewhere around. To use the ADO constants in VBScript you need the line

    Code:
    <!-- #include file="adovbs.inc" -->
    at the beginning of your script. Put the adovbs.inc file in the same directory as the script you are running. You could , alternatively, put

    Code:
    <!-- #include virtual="/the/file/path/adovbs.inc" -->
    if you wanted to keep it somewhere else and reference it by it's virtual location.
    Harry.

    "From one thing, know ten thousand things."

  9. #9
    Guest
    Ah! And that file has constants like:

    adOpenKeyset
    adLockPessimistic

    I kinda thought that these constants were build into the asp interpreter...like all the "vb..." constants in vb...suppose they are actually contained in the runtime dlls that asp doesn's have...not being vb and all.

    Oh well whatever. It works now and i've learned something so that's all i care about.

    Cheers everyone!

  10. #10
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    Yeah it was kind of a revelation to me too

    Maybe now I'll be able to get those fricking bookmarks to work!

    Harry.

    "From one thing, know ten thousand things."

  11. #11
    Guest
    sorry! what? what bookmarks? :?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width