【问题标题】:asp sql server connection and tableasp sql server 连接和表
【发布时间】:2026-02-05 08:05:02
【问题描述】:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
 <title>SOP</title>
</head>

<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td align="left">

<%
selectdata= "Select * from dbo.sop"


set RScontest = Server.CreateObject("ADODB.Recordset")
RScontest.ActiveConnection = "dsn=test123 ;uid=test123;pwd=test123"
RScontest.Source = SelectData
RScontest.CursorType = 3
RScontest.CursorLocation = 2
RScontest.LockType = 1
RScontest.Open()
if not(rscontest.bof) and not(rscontest.eof) then%>
%>

<table BORDER="1" align="center" width="640">
<caption>SOP</caption>
<tr>
<td>Order</td>
<td>Department</td>
<td>DOC Type</td>
<td>Title</td>
<td>Revision</td>
<td>DOC</td>
<td>Active</td>

<%
 while not rscontest.eof
%>

<tr>
<td>
<%= rs("order") %>
</td>

<td>
<%= rs("Department") %>
</td>

<td>
<%= rs("[DOC Type]") %>
</td>

<td>
<%= rs("Title") %>
</td>

<td>
<%= rs("Revision") %>
</td>

<td>
<%= rs("DOC") %>
</td>

<td>
<%= rs("Active") %>
</td>

 <%
' Move to the next record
rs.movenext
' Loop back to the do statement
loop %>
</table>

</body>
</html>

<%
' Close and set the recordset to nothing
rs.close
set rs=nothing
%>

Microsoft VBScript 运行时错误“800a01a8”是我遇到的错误。

如果您可以帮助我使用 OLEDB 方式进行连接,您也可以检查一下吗?我尝试了自己,但无法正常工作。

【问题讨论】:

    标签: sql asp-classic vbscript ado


    【解决方案1】:

    您的代码没有显示您定义或打开数据库连接。

    您需要先定义它,然后将它与您要执行的查询一起传递到记录集

    这里打开连接的详细信息:http://msdn.microsoft.com/en-us/library/ms807027.aspx

    该 MDSN 文章中的代码示例:

    Sub ConnectionExample6()
       Dim cnn As ADODB.Connection
       Dim rs As ADODB.Recordset
    
       Set cnn = New ADODB.Connection
    
       ' Open a connection by referencing the ODBC driver.
       cnn.ConnectionString = "driver={SQL Server};" & _
          "server=MySqlServer;uid=MyUserName;pwd=MyPassword;database=pubs"
       cnn.Open
    
       ' Create a Recordset by executing an SQL statement.
       Set rs = cnn.Execute("Select * From authors")
    
       ' Show the first author.
       MsgBox rs("au_fname") & " " & rs("au_lname")
    
       ' Close the connection.
       rs.Close
    
    End Sub
    

    【讨论】:

    • 但是我添加表格的方式是正确的,我怎么能做到这种oledb风格。