源代码:<%@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)
    ~~~~~~~~~~~~~~        
究竟是什么原因?

解决方案 »

  1.   

    第一个SQLCmd = New SQLCommand(SQLText,cnString)中的cnString参数应当为SqlConnection类型最后的错误应该这样表示dbRead = SQLCmd.ExectueReader()
      

  2.   

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

  3.   

    你需要创建一个SqlConnection对象,
    Dim myConnection As New SqlConnection = New SqlConnection(cnString)
    myConnection.Open()
    SQLCmd = New SQLCommand(SQLText,myConnection)
      

  4.   

    又出现了新的问题
    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()
      

  5.   

    非常感谢大家的帮忙,真诚的感谢.请再接再厉.thankyou