Asp.net (VB.net) connection module of the SQL Server 2000 database

Source: Internet
Author: User
Module mdlcommon
Public txtsql as string' stores SQL statements
Public dbset as Dataset
Public errormsg as string' stores error messages

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 calling, write txtsql = "Select... from..." in the Asp.net background ........";
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.