0

我昨天问了这个问题并得到了答案。我通读了它并认为它可以工作,但是在将代码实现到我的 .asp 页面后,我得到了一个错误。

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
%>

错误说

“Microsoft VBScript 编译错误‘800a0401’

预期的语句结束

将 myList 调暗为 List(Of String) = rsLogbook("sensors").ToString().Split(New () {","}, StringSplitOptions.RemoveEmptyEntries).ToList() ------------ ^

我真的很感激这方面的任何帮助。

我在这里尝试使用此代码做的是从数据库中提取信息并使用 .asp 和 VB 脚本将其显示在网页中。我正在使用.asp页面中的Response.Write标签来实现包含数据库中信息的字段名称

更新

<%
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
%>

这也是其中包含数据库和表名的实际代码

4

1 回答 1

2

如果您只想从数据库中检索一个字段并 Response.Write 所有行,您可以使用这样的东西。请注意,我已删除 VB.NET 代码来创建列表。我还在 SQL 查询中添加了 WHERE 子句,以防您不想要空值(根据 VB.NET),并添加了 ORDER BY 子句来替换 List 排序。

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
于 2013-04-12T05:28:16.357 回答