asp.net (vb.net) connection module (module) for SQL Server 2000 database

Source: Internet
Author: User
asp.net|server| Data | database Module Mdlcommon
Public txtsql as String ' holds SQL statements
Public dbset as DataSet ' query-obtained recordset
Public errormsg as String ' holds error message

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
When called, write the txtsql= "SELECT" in the asp.net background. From ... ";
Dbset=executesql (TXTSQL,ERRORMSG)





Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.