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