DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 9 of 9

Thread: Accessing Database

  1. #1
    Join Date
    May 2007
    Posts
    59

    Accessing Database

    Ok, so on a page, I want to access an Access Database I created. I just want to show some names and a link to a page with an id attached.

    I create my database using:
    Code:
    dim cnn
    
    set cnn = server.createobject("ADODB.connection")
    
    with cnn
        .Provider = "Microsoft.Jet.OLEDB.4.0"
    	.ConnectionString = Server.MapPath("/S5047049/HerEx/Include") & "/Studeerwijzer.mdb"
    	.open
    end with
    Then I open a recordset with
    Code:
    dim rst, strOpen
    set rst = server.CreateObject("ADODB.Recordset")
    strOpen = "Select * from tblOpleiding order by OpleidingNaam"
    rst.Open strOpen, cnn, adOpenStatic, adLockOptimistic
    And I show the data with:
    Code:
    <%= rst.Fields("opleidingNaam") %>
    In between is a bit of HTML code, but nothing of matter.

    The odd thing is, when I execute this on my server. I get the following error:
    ADODB.Recordset error '800a0bb9'

    Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another.

    /s5047049/HerEx/studeerwijzerKeuze.asp, line 42
    Line 42 is:
    Code:
    rst.Open strOpen, cnn, adOpenStatic, adLockOptimistic
    Anybody got an idea where I did something wrong?

  2. #2
    Join Date
    Dec 2003
    Posts
    2,750
    This looks like ASP code so I'm assuming that somewhere in your code you have defined values for adOpenStatic and adLockOptimistic?
    Paul
    ~~~~
    Microsoft MVP (Visual Basic)

  3. #3
    Join Date
    May 2007
    Posts
    59
    Nop, those are standard values that you can choose when you type in:

    Code:
    rst.Open strOpen, cnn,
    Once that is typed you get a drop down box with 4 choices and those are one of the choices.

  4. #4
    Join Date
    Dec 2003
    Posts
    2,750
    OK, try replacing those variables with their actual values (3 and 3) and see what happens when you run the code.
    Paul
    ~~~~
    Microsoft MVP (Visual Basic)

  5. #5
    Join Date
    May 2007
    Posts
    59
    My hero! It works.

  6. #6
    Join Date
    May 2007
    Posts
    59
    Yeah, I'm back with a new question. (I got a feeling there are a lot of questions going to follow. )

    I can access my database normally, no problem there. But when I run a query on my local database it returns 3 values. When I want to show those three values on my webpage, he leaves out the middle value. Any ideas?

  7. #7
    Join Date
    Dec 2003
    Posts
    2,750
    The reason it works is because ASP doesn't have global access to the values of adOpenStatic and adLockOptimistic in the ADODB library. That's why you have to define them in your code if you want to use them.
    Paul
    ~~~~
    Microsoft MVP (Visual Basic)

  8. #8
    Join Date
    Dec 2003
    Posts
    2,750
    Quote Originally Posted by Armaron
    Yeah, I'm back with a new question. (I got a feeling there are a lot of questions going to follow. )

    I can access my database normally, no problem there. But when I run a query on my local database it returns 3 values. When I want to show those three values on my webpage, he leaves out the middle value. Any ideas?
    You will probably need to post some code so that we can see what you are doing.
    Paul
    ~~~~
    Microsoft MVP (Visual Basic)

  9. #9
    Join Date
    May 2007
    Posts
    59
    Ok, code first, explanation later:

    Code:
    strOpen = "Select * from tblOpleidingsOnderdeel where OpleidingsOndID in 
      (select OpleidingsOndID from tblOnderwijsActiviteit where OpleidingID = " &
      Request.QueryString("opleidingID") & ") order by OpleidingsOnderdeelNaam"
    rst.Open strOpen, cnn, 3, 2
    Response.Write("<h3>" & Request.QueryString("naam") & "</h3>")
    do while not rst.EOF
      Response.Write("<li><a href=""./studeerwijzerKeuze.asp?oo=" &  rst.Fields("OpleidingsOndID") &
      "&opleidingID=" & Request.QueryString("opleidingID") & "&naam=" &
        Request.QueryString("naam") & "&oplond=" & rst.Fields("OpleidingsOnderdeelNaam") & """>" &
        rst.Fields("OpleidingsOnderdeelNaam") & "</a></li>")
    rst.MoveNext
    loop
    strOpen is my SQL statement. I ran the statement on my local database (it's just an Access database on my server) and there it gives three output lines. On my website just two. I replaced the "Request.QueryString("opleidingID")" with a value that would be implemented if I would use it on the server. So that I was sure that I am using the same values as when I click my link that leads to this bit of code.
    the Do While Loop is the space where the recordset is printed to my screen.
    Last edited by Armaron; 07-19-2007 at 09:02 AM.

Similar Threads

  1. Replies: 1
    Last Post: 03-12-2007, 09:56 AM
  2. Accessing Password Protected Database.
    By Jim in forum VB Classic
    Replies: 3
    Last Post: 07-04-2002, 02:38 AM
  3. Accessing Access Database
    By jim in forum VB Classic
    Replies: 5
    Last Post: 03-23-2001, 01:53 PM
  4. Accessing Multiple database backends
    By Steven Reid in forum VB Classic
    Replies: 1
    Last Post: 08-12-2000, 09:25 AM
  5. Accessing .jpg files in a database
    By Jeff in forum VB Classic
    Replies: 2
    Last Post: 06-16-2000, 03:38 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center