Fill Listbox with Data from Access DB

Fill Listbox with Data from Access DB

am 28.01.2005 09:57:27 von Eddy Scheire

Hi Everyone,

I got this code on a .asp page that retrieves data from an AccessDB and
shows it in a table.

<%

Dim DB
Set DB = Server.CreateObject ("ADODB.Connection")
DB.Open ("Provider=Microsoft.Jet.OLEDB.4.0; DATA SOURCE= " +
Server.MapPath("Muziek.mdb"))

Dim RS
Set RS = Server.CreateObject ("ADODB.Recordset")
RS.Open "SELECT * FROM Namen WHERE Genre='HR' ORDER BY Naam ASC", DB

If rs.RecordCount = 0 Then
Response.Write("No records found for category ")
Else
Response.Write("

Items Found for Category:

")
' Build a table here
Response.Write(" BGCOLOR=#F0F0FF>")
Response.Write("")
Response.Write("")
Response.Write("")
Response.Write("")
Do While Not RS.EOF
Response.Write("")
Response.Write("")
Response.Write("")
Response.Write("")
RS.MoveNext
Loop
RS.Close
Response.Write("
BGCOLOR=#C8C8FF>Nummer BGCOLOR=#C8C8FF>Naam
" & RS("Nummer") & "" & RS("Naam") & "
")
End If

%>

But I want to get the results of the query in a listbox on this page. I've
found several examples on the net but unfortunately none of them worked! Can
somebody get me some simple working code, please?

Thanx
Eddy

Re: Fill Listbox with Data from Access DB

am 28.01.2005 12:08:39 von McKirahan

"Eddy Scheire" wrote in message
news:41f9fe77$0$557$ba620e4c@news.skynet.be...
> Hi Everyone,
>
> I got this code on a .asp page that retrieves data from an AccessDB and
> shows it in a table.
>
> <%
>
> Dim DB
> Set DB = Server.CreateObject ("ADODB.Connection")
> DB.Open ("Provider=Microsoft.Jet.OLEDB.4.0; DATA SOURCE= " +
> Server.MapPath("Muziek.mdb"))
>
> Dim RS
> Set RS = Server.CreateObject ("ADODB.Recordset")
> RS.Open "SELECT * FROM Namen WHERE Genre='HR' ORDER BY Naam ASC", DB
>
> If rs.RecordCount = 0 Then
> Response.Write("No records found for category ")
> Else
> Response.Write("

Items Found for Category:

")
> ' Build a table here
> Response.Write(" > BGCOLOR=#F0F0FF>")
> Response.Write("")
> Response.Write("")
> Response.Write("")
> Response.Write("")
> Do While Not RS.EOF
> Response.Write("")
> Response.Write("")
> Response.Write("")
> Response.Write("")
> RS.MoveNext
> Loop
> RS.Close
> Response.Write("
> BGCOLOR=#C8C8FF>Nummer > BGCOLOR=#C8C8FF>Naam
" & RS("Nummer") & "" & RS("Naam") & "
")
> End If
>
> %>
>
> But I want to get the results of the query in a listbox on this page. I've
> found several examples on the net but unfortunately none of them worked!
Can
> somebody get me some simple working code, please?
>
> Thanx
> Eddy


Is this what you want?

<%
Dim DB
Set DB = Server.CreateObject ("ADODB.Connection")
DB.Open ("Provider=Microsoft.Jet.OLEDB.4.0; DATA SOURCE= " &
Server.MapPath("Muziek.mdb"))

Dim RS
Set RS = Server.CreateObject ("ADODB.Recordset")
RS.Open "SELECT * FROM Namen WHERE Genre='HR' ORDER BY Naam ASC", DB

If RS.RecordCount = 0 Then
Response.Write("No Items found for Category.")
Else
Response.Write("

Items Found for Category:

")
Response.Write("")
End If
RS.Close
Set RS = Nothing
DB.Close
Set DB = Nothing
%>

I changed one "+" to "&" and onr "rs." to "RS.", as well as closing and
destroying objects when through.

Re: Fill Listbox with Data from Access DB

am 28.01.2005 12:28:39 von reb01501

Eddy Scheire wrote:
> Hi Everyone,
>
> I got this code on a .asp page that retrieves data from an AccessDB
> and shows it in a table.
>
> <%
>
> Dim DB
> Set DB = Server.CreateObject ("ADODB.Connection")
> DB.Open ("Provider=Microsoft.Jet.OLEDB.4.0; DATA SOURCE= " +
> Server.MapPath("Muziek.mdb"))
>
> Dim RS
> Set RS = Server.CreateObject ("ADODB.Recordset")
> RS.Open "SELECT * FROM Namen WHERE Genre='HR' ORDER BY Naam ASC", DB
>
> If rs.RecordCount = 0 Then

This will not work with the default cursor. Change it to:

If not rs.EOF tnen


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"

Re: Fill Listbox with Data from Access DB

am 28.01.2005 12:31:08 von reb01501

Oops. Slight error. See below:
Eddy Scheire wrote:
> Hi Everyone,
>
> I got this code on a .asp page that retrieves data from an AccessDB
> and shows it in a table.
>
> <%
>
> Dim DB
> Set DB = Server.CreateObject ("ADODB.Connection")
> DB.Open ("Provider=Microsoft.Jet.OLEDB.4.0; DATA SOURCE= " +
> Server.MapPath("Muziek.mdb"))
>
> Dim RS
> Set RS = Server.CreateObject ("ADODB.Recordset")
> RS.Open "SELECT * FROM Namen WHERE Genre='HR' ORDER BY Naam ASC", DB
>
> If rs.RecordCount = 0 Then

This will not work with the default cursor. Change it to:

If rs.EOF tnen


Bob Barrows