asp.net connection database Add, modify, delete, query code _ Practical skills

Source: Internet
Author: User
Copy Code code as follows:

' Database connection
Public Sub connectiondb ()
Try

ServerURL = Readfromini (My.Application.Info.DirectoryPath & "\config.dll", "Service Information", "IPAddress")

ServerID = Readfromini (My.Application.Info.DirectoryPath & "\config.dll", "Service Information", "Password")
ServerName = Readfromini (My.Application.Info.DirectoryPath & "\config.dll", "Service Information", "UserID")
Serverdatabase = Readfromini (My.Application.Info.DirectoryPath & "\config.dll", "Service Information", " DataBaseName ")
If serverid <> "" Then
connectionsqlstring = "Server =" + ServerURL + ";D atabase=" + serverdatabase + "; uid =" + serverName + ";p wd=" + ServerID + "; Max Pool size=500"
Else
connectionsqlstring = "Server = & ServerURL &" Integrated Security = SSPI;d atabase = "& Serverdatabase &am P ""
End If
Consql = New SqlConnection (connectionsqlstring)
Objcommand.connection = Consql
Catch ex as Exception
MsgBox (ex. Message)
End Try
End Sub


' Data operation execution
Public Sub Getconn (ByVal sqlstr As String, ByVal tablename As String)
Try
Objcommand.commandtext = Sqlstr
Objdataset.clear ()
Objdataadapter.selectcommand = Objcommand
Objdataadapter.fill (Objdataset, TableName)
Catch ex as Exception
ErrNo = 1
MsgBox (ex. Message)
End Try
End Sub
' Data update
Public Sub updatetable (ByVal strSQL as String)
Objcommand.commandtext = strSQL
Try
Consql.open ()
Trans = Consql.begintransaction
Objcommand.transaction = Trans
Objcommand.executenonquery ()
Trans.commit ()
Catch ESE as Exception
MsgBox (ESE. Message)
Trans.rollback () ' Cancel all updates if update exception
Finally
Consql.close () ' Close connection
End Try
End Sub
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.