CopyCode The Code is 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 + "; database = "+ serverdatabase +"; uid = "+ servername +"; Pwd = "+ serverid + "; max pool size = 500 "
else
connectionsqlstring =" Server = "& serverurl &"; Integrated Security = sspi; database = "& serverdatabase &" "
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 () 'If an update exception occurs, cancel all updates
finally
consql. close () 'close the connection
end try
end sub