1

我想将我的网页从 Asp 经典转换为 Asp.net (VB),我应该做什么来代替这段代码?

连接.asp:

<%
    Dim conn,connstr
        connstr = "Provider=sqloledb; Data Source=.\SQLEXPRESS ;Initial Catalog=My_DB ;User Id=sa;Password=12345"
        on error resume next
        set conn=server.createobject("ADODB.CONNECTION")
        conn.open connstr
            if err then
                err.clear
                set conn=nothing
                response.write "Connect Error!"
                response.End         
            End IF

    %>

感谢您的时间!

4

1 回答 1

1

在 C# 中

using (SqlConnection connection = new SqlConnection("Provider=sqloledb; Data Source=.\SQLEXPRESS ;Initial Catalog=My_DB ;User Id=sa;Password=12345"))
{
    connection.Open();
    // Do work here; connection closed on following line.
}

VB.NET

Using connection As New SqlConnection("Provider=sqloledb; Data Source=.\SQLEXPRESS ;Initial Catalog=My_DB ;User Id=sa;Password=12345")
    connection.Open()
    // Do work here; connection closed on following line. 
End Using 

可以在这里找到各种连接字符串

于 2013-06-04T06:42:14.747 回答