源代码:<%@import namespace="System.Data.SqlClient"%>
<script language="VB" runat="server">
Sub Page_Load(sender As Object, e As EventArgs)
Dim SQLText as String = "SELECT * FROM authors"
Dim cnString as string = "server=localhost;uid=sa;pwd=;database=pubs;"
Dim dbRead AS SQLDataReader
Dim SQLCmd AS SQLCommand SQLCmd = New SQLCommand(SQLText,cnString)
SQLCmd.ActiveConnection.Open() SQLCmd.execute(dbread) while dbRead.Read()
response.write("<br>" & dbRead.Item("au_lname"))
End whileEnd Sub
</script>
提示错误:\index.aspx(9) : error BC30311: 类型“String”的值无法转换为“System.Data.SqlClient.SqlConnection”。 SQLCmd = New SQLCommand(SQLText,cnString)
~~~~~~~~
E:\index.aspx(10) : error BC30456: “ActiveConnection”不是“System.Data.SqlClient.SqlCommand”的成员。 SQLCmd.ActiveConnection.Open()
~~~~~~~~~~~~~~~~~~~~~~~
E:\index.aspx(12) : error BC30456: “execute”不是“System.Data.SqlClient.SqlCommand”的成员。 SQLCmd.execute(dbread)
~~~~~~~~~~~~~~
究竟是什么原因?
<script language="VB" runat="server">
Sub Page_Load(sender As Object, e As EventArgs)
Dim SQLText as String = "SELECT * FROM authors"
Dim cnString as string = "server=localhost;uid=sa;pwd=;database=pubs;"
Dim dbRead AS SQLDataReader
Dim SQLCmd AS SQLCommand SQLCmd = New SQLCommand(SQLText,cnString)
SQLCmd.ActiveConnection.Open() SQLCmd.execute(dbread) while dbRead.Read()
response.write("<br>" & dbRead.Item("au_lname"))
End whileEnd Sub
</script>
提示错误:\index.aspx(9) : error BC30311: 类型“String”的值无法转换为“System.Data.SqlClient.SqlConnection”。 SQLCmd = New SQLCommand(SQLText,cnString)
~~~~~~~~
E:\index.aspx(10) : error BC30456: “ActiveConnection”不是“System.Data.SqlClient.SqlCommand”的成员。 SQLCmd.ActiveConnection.Open()
~~~~~~~~~~~~~~~~~~~~~~~
E:\index.aspx(12) : error BC30456: “execute”不是“System.Data.SqlClient.SqlCommand”的成员。 SQLCmd.execute(dbread)
~~~~~~~~~~~~~~
究竟是什么原因?
<script language="VB" runat="server">
Sub Page_Load(sender As Object, e As EventArgs)
Dim SQLText as String = "SELECT * FROM authors"
Dim cnString as string = "server=localhost;uid=sa;pwd=;database=pubs;"
Dim myConnection As New SqlConnection = New SqlConnection(cnString)
Dim dbRead AS SQLDataReader
Dim SQLCmd AS SQLCommand SQLCmd = New SQLCommand(SQLText,myConnection)
SQLCmd.ActiveConnection.Open() SQLCmd.execute(dbread) while dbRead.Read()
response.write("<br>" & dbRead.Item("au_lname"))
End whileEnd Sub
</script>
Dim myConnection As New SqlConnection = New SqlConnection(cnString)
myConnection.Open()
SQLCmd = New SQLCommand(SQLText,myConnection)
E:\index.aspx(6) : error BC30205: 需要语句结束。 Dim myConnection As New SqlConnection = New SqlConnection(cnString)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
E:\index.aspx(10) : error BC30451: 名称“myconnection”未声明。 sqlcmd=new sqlcommand(sqltext,myconnection)
~~~~~~~~~~~~
E:\index.aspx(11) : error BC30456: “activeconnection”不是“System.Data.SqlClient.SqlCommand”的成员。 sqlcmd.activeconnection.open()
~~~~~~~~~~~~~~~~~~~~~~~
E:\index.aspx(12) : error BC30456: “ExectueReader”不是“System.Data.SqlClient.SqlCommand”的成员。 dbRead = SQLCmd.ExectueReader()