Professional Web Applications Themes

Newbee need help. - ASP Database

I am new to ASP and i am having some dificulities here and there. I can not get the following code to wor like i want it to. I do not get any messages that says that is something wrong bot there is no data from the DB(ACCESS) displayed in the selectbox. Wold be very gratefull if someone could tell me why. The Newbwee. <% dim dbconn, rsTeaterStk set dbconn = Server.createobject("ADODB.Connection") dbconn.connectionstring = _ "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Inetpub\wwwroot\telia\telia.mdb" dbconn.open set rsTeaterStk = Server.createobject("ADODB.Recordset") rsTeaterStk.open "SELECT teaterstykke.forestillingsnavn FROM teaterstykke",dbconn %> <h1>Velg teaterstykket som du har lyst se </h1> <form action="start.asp" method="post"> ...

  1. #1

    Default Newbee need help.

    I am new to ASP and i am having some dificulities here and there.
    I can not get the following code to wor like i want it to. I do not get
    any messages that says that is something wrong bot there is no data from
    the DB(ACCESS) displayed in the selectbox.

    Wold be very gratefull if someone could tell me why.


    The Newbwee.


    <%
    dim dbconn, rsTeaterStk
    set dbconn = Server.createobject("ADODB.Connection")
    dbconn.connectionstring = _
    "Provider=Microsoft.Jet.OLEDB.4.0;Data
    Source=C:\Inetpub\wwwroot\telia\telia.mdb"
    dbconn.open
    set rsTeaterStk = Server.createobject("ADODB.Recordset")

    rsTeaterStk.open "SELECT teaterstykke.forestillingsnavn FROM
    teaterstykke",dbconn


    %>
    <h1>Velg teaterstykket som du har lyst se </h1>
    <form action="start.asp" method="post">
    <table width="400">
    <tr>
    <td>Velg Teaterstykke</td>
    <td>
    <select name="Teaterstykke">
    <%while not rsTeaterStk.eof
    response.write "<option value='" & rsTeaterStk("forestillingsnavn") & "'>"
    response.write rsTeaterStk("forestillingsnavn") & "</option>"
    rsTeaterStk.movenext
    wend
    rsTeaterStk.close%>
    <option value="Alle">Alle</option>
    </select>
    Erik Guest

  2. #2

    Default Re: Newbee need help.

    Erik .F wrote: 

    No errors? Do you have "On Error Resume Next" anywhere in your page?
     

    Does the "Alle" option display? 

    If you run this query using the Access Query Builder, does it give you the
    intended results?
     


    I'd prefer to see
    Do Until rsTeaterStk.EOF
    ....
    Loop

    But this should work.

    I suggest that you use GetRows instead of the slow, inefficient recordset
    loop, and add a little extra code for debugging (especially "Option
    Explicit"):

    <%
    Option Explicit
    dim dbconn, rsTeaterStk, sSQL, arData
    dim arOptions(), sOptions, i
    Const adCmdText = 1
    set dbconn = Server.createobject("ADODB.Connection")
    dbconn.connectionstring = _
    "Provider=Microsoft.Jet.OLEDB.4.0;Data
    Source=C:\Inetpub\wwwroot\telia\telia.mdb"
    dbconn.open
    sSQL= "SELECT forestillingsnavn FROM teaterstykke"

    'for debugging only:
    response.write sSQL
    'remove the above line when debugging is complete

    set rsTeaterStk = dbconn.Execute(sSQL,,adCmdText)
    if not rsTeaterStk.EOF then arData = rsTeaterStk.GetRows
    rsTeaterStk.close: Set rsTeaterStk =Nothing
    dbconn.close:set cbconn=nothing

    if not isArray(arData) then
    response.write "The query returned no data.<BR>"
    else
    redim arOptions(Ubound(arData,2))
    for i = 0 to Ubound(arData,2)
    arOptions(i) = "<option value=""" & arData(0,i) & """>" & _
    arData(0,i) & "</option>"
    next
    sOptions = Join(arOptions,vbcrlf)
    end if
    %>
    <h1>Velg teaterstykket som du har lyst se </h1>
    <form action="start.asp" method="post">
    <table width="400">
    <tr>
    <td>Velg Teaterstykke</td>
    <td>
    <select name="Teaterstykke">
    <%=sOptions%>
    <option value="Alle">Alle</option>
    </select>
    </td></tr></table



    HTH,
    Bob Barrows

    --
    Microsoft MVP - ASP/ASP.NET
    Please reply to the newsgroup. This email account is my spam trap so I
    don't check it very often. If you must reply off-line, then remove the
    "NO SPAM"


    Bob Guest

  3. #3

    Default Re: Newbee need help.

    Bob Barrows [MVP] wrote:
     
    >
    >
    > No errors? Do you have "On Error Resume Next" anywhere in your page?
    >

    >
    >
    > Does the "Alle" option display?

    >
    >
    > If you run this query using the Access Query Builder, does it give you the
    > intended results?
    >

    >
    >
    >
    > I'd prefer to see
    > Do Until rsTeaterStk.EOF
    > ...
    > Loop
    >
    > But this should work.
    >
    > I suggest that you use GetRows instead of the slow, inefficient recordset
    > loop, and add a little extra code for debugging (especially "Option
    > Explicit"):
    >
    > <%
    > Option Explicit
    > dim dbconn, rsTeaterStk, sSQL, arData
    > dim arOptions(), sOptions, i
    > Const adCmdText = 1
    > set dbconn = Server.createobject("ADODB.Connection")
    > dbconn.connectionstring = _
    > "Provider=Microsoft.Jet.OLEDB.4.0;Data
    > Source=C:\Inetpub\wwwroot\telia\telia.mdb"
    > dbconn.open
    > sSQL= "SELECT forestillingsnavn FROM teaterstykke"
    >
    > 'for debugging only:
    > response.write sSQL
    > 'remove the above line when debugging is complete
    >
    > set rsTeaterStk = dbconn.Execute(sSQL,,adCmdText)
    > if not rsTeaterStk.EOF then arData = rsTeaterStk.GetRows
    > rsTeaterStk.close: Set rsTeaterStk =Nothing
    > dbconn.close:set cbconn=nothing
    >
    > if not isArray(arData) then
    > response.write "The query returned no data.<BR>"
    > else
    > redim arOptions(Ubound(arData,2))
    > for i = 0 to Ubound(arData,2)
    > arOptions(i) = "<option value=""" & arData(0,i) & """>" & _
    > arData(0,i) & "</option>"
    > next
    > sOptions = Join(arOptions,vbcrlf)
    > end if
    > %>
    > <h1>Velg teaterstykket som du har lyst se </h1>
    > <form action="start.asp" method="post">
    > <table width="400">
    > <tr>
    > <td>Velg Teaterstykke</td>
    > <td>
    > <select name="Teaterstykke">
    > <%=sOptions%>
    > <option value="Alle">Alle</option>
    > </select>
    > </td></tr></table
    >
    >
    >
    > HTH,
    > Bob Barrows
    >[/ref]
    Thanks for your reply Bob.
    I have now solved the problem. There was a rather silliy mistake made by
    me(I am a newbee). Wrong referance to mdb file was the prob here. I have
    two you see, one emty backup and one with data in.

    Yor example is more advanced and better, and I will use your
    modifications. Again thank you very much.

    Erik




    Erik Guest

  4. #4

    Default Re: Newbee need help.


    "Erik .F" <net> wrote in message
    news:_lQ7d.869$dax.net... 

    It may be that you do get an error message, but it gets written into the
    select box, which the browser considers as a syntax error and doesn't
    displays it. Always try to view the page source (by 'view source' in the
    browser), and go to the bottom. Especially when you get empty SELECT's and
    the rest of the page after it doesn't get displayed.
     


    Agoston Guest

Similar Threads

  1. newbee question
    By Charlies Angel in forum Macromedia Flash Flashcom
    Replies: 7
    Last Post: February 11th, 06:42 PM
  2. Newbee on Fonts; converting from Mac to PC
    By Jim_Strzyzewski@adobeforums.com in forum Adobe Indesign Windows
    Replies: 6
    Last Post: May 3rd, 04:41 PM
  3. Help needed - mod_perl -Newbee
    By star night in forum PERL Modules
    Replies: 2
    Last Post: April 20th, 11:16 AM
  4. newbee help with php please
    By erik in forum PHP Development
    Replies: 0
    Last Post: September 13th, 01:11 PM
  5. ORA-00600 ... more exactly (from a newbee)
    By Karsten Farrell in forum Oracle Server
    Replies: 5
    Last Post: January 3rd, 08:30 AM

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
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139