Reputation: 63
I asked this question yesterday and got an answer. I read through it and thought it would work but after implementing the code to my .asp page im getting an error.
Dim strSQL
Set adoCon = Server.CreateObject("ADODB.Connection")
adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("DatabaseName.mdb")
Set rsLogbook = Server.CreateObject("ADODB.Recordset")
strSQL = "SELECT TableName.FieldName FROM TableName;"
rsLogbook.Open strSQL, adoCon
'' get string and put into list
Dim myList As List(Of String) = rsLogbook("FieldName").ToString().Split(New () {","}, StringSplitOptions.RemoveEmptyEntries).ToList()
'' then close all your stuff
rsLogbook.Close
Set rsLogbook = Nothing
Set adoCon = Nothing
'' Sort your list
myList.Sort();
'' now output to where ever you want.
'' in this case, have an asp.literal control on your page where you want the text and call it myLit
For each sensor in myList
myLit.Text += "<p>" + sensor + "</p>"
Next
%>
The error says
"Microsoft VBScript compilation error '800a0401'
Expected end of statement
Dim myList As List(Of String) = rsLogbook("sensors").ToString().Split(New () {","}, StringSplitOptions.RemoveEmptyEntries).ToList() -----------^
I would really appreciate any help with this.
What i am trying to do here using this code is to pull information off of a database and display it in a webpage using .asp and VB script. I'm using the Response.Write tags in the .asp page to implement the field name that contains the information in the database
UPDATE
<%
Dim adoCon
Dim rsLogbook
Dim strSQL
Set adoCon = Server.CreateObject("ADODB.Connection")
adoCon.Open "DRIVER={Microsoft Access Driver (*accdb, *.mdb)}; DBQ=" & Server.MapPath("featuredvehicle.accdb")
Set rsLogbook = Server.CreateObject("ADODB.Recordset")
strSQL = "SELECT featuredvehicles.make FROM featuredvehicles;"
rsLogbook.Open strSQL, adoCon
Response.Write ("<br>")
Response.Write (rsLogbook("make"))
rsLogbook.Close
Set rsLogbook = Nothing
Set adoCon = Nothing
%>
This is the actual code with the database and table names in it as well
Upvotes: 0
Views: 172
Reputation: 10752
If all you want to do is retrieve a field from the database and Response.Write all rows, you could use something like this. Note that I have removed the VB.NET code to create a List. I also added a WHERE clause to your SQL query in case you don't want empty values (as per the VB.NET) and added an ORDER BY clause to replace the List sort.
Dim strSQL
Set adoCon = Server.CreateObject("ADODB.Connection")
adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("DatabaseName.mdb")
Set rsLogbook = Server.CreateObject("ADODB.Recordset")
strSQL = "SELECT TableName.FieldName FROM TableName WHERE TableName.FieldName != '' ORDER BY TableName.FieldName ASC;" 'Add order by clause so you don't need to sort the array
rsLogbook.Open strSQL, adoCon
Do Until rsLogBook.EOF
Response.Write(rsLogbook("FieldName")) & "<br />"
rsLogBook.MoveNext
Loop
rsLogbook.Close
Set rsLogbook = Nothing
Set adoCon = Nothing
Upvotes: 2