发现代码中的错误是什么

时间:2013-04-11 13:51:50

标签: database asp-classic vbscript

昨天我问this question并得到答案。我仔细阅读并认为它可以工作但是在我的.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'

     

预期声明结束

     

Dim myList As 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
%>

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

1 个答案:

答案 0 :(得分:2)

如果您要做的只是从数据库中检索字段并且Response.Write所有行,您可以使用类似的东西。请注意,我已删除VB.NET代码以创建List。我还为您的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