欢迎光临
我们一直在努力

asp.net(vb.net)连接sql server 2000数据库的连接模块(module) _asp.net技巧

建站超值云服务器,限时71元/月

Module MdlCommon
    Public txtSQL As String     存放SQL语句
    Public DBSet As DataSet     查询得到的记录集
    Public ErrorMsg As String   存放错误信息 


    Public Function ExecuteSQL(ByVal strSQL As String, ByRef errMsg As String) As DataSet
        Dim cnn As SqlClient.SqlConnection
        Dim cmd As New SqlClient.SqlCommand()
        Dim adpt As SqlClient.SqlDataAdapter
        Dim rst As New DataSet()
        Dim SplitSQL() As String
        errMsg = “”
        Try
            SplitSQL = Split(strSQL)
            cnn = New SqlClient.SqlConnection(“data source=(local);initial catalog=urp;user id=sa;pwd=1234”)


            If InStr(“INSERT,DELETE,UPDATE”, UCase$(SplitSQL(0))) Then
                cmd.Connection = cnn
                cmd.Connection.Open()
                cmd.CommandText = strSQL
                cmd.ExecuteNonQuery()
            Else
                adpt = New SqlClient.SqlDataAdapter(strSQL, cnn)
                adpt.Fill(rst)
                ExecuteSQL = rst
            End If
        Catch ex As Exception
            errMsg = ex.Message
        Finally
            rst = Nothing
            cnn = Nothing
        End Try
    End Function End Module
调用时在asp.net后台写上txtSQL=”SELECT ….FROM……..”;
DBSet=ExecuteSQL(txtSQL,ErrorMsg)

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » asp.net(vb.net)连接sql server 2000数据库的连接模块(module) _asp.net技巧
分享到: 更多 (0)