Asp.net adds, modifies, deletes, and queries the database code.

Source: Internet
Author: User

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

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.