asp.net连接数据库 增加,修改,删除,查询代码
程序员文章站
2024-03-09 08:24:17
复制代码 代码如下:'数据库连接 public sub connectiondb() try serverurl = readfromini(my.application....
复制代码 代码如下:
'数据库连接
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
'数据操作执行
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
'数据更新
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() '如果更新异常则取消所有更新
finally
consql.close() '关闭连接
end try
end sub
上一篇: 使用WAMP搭建PHP本地开发环境
下一篇: 深入理解Java遗传算法
推荐阅读
-
asp.net连接数据库 增加,修改,删除,查询代码
-
C#连接操作MySQL数据库进行添加、修改、删除、查询等操作的演示
-
mysql-数据库操作-连接-创建-删除-修改编码-查询-切换
-
PHP轻量级数据库操作类Medoo增加、删除、修改、查询例子
-
PHP中MongoDB数据库的连接、添加、修改、查询、删除等操作实例
-
PHP轻量级数据库操作类Medoo增加、删除、修改、查询例子
-
PHP轻量级数据库操作类Medoo增加、删除、修改、查询例子_PHP教程
-
php 连接 access数据库与修改 删除 增加 数据实例
-
PHP中MongoDB数据库的连接、添加、修改、查询、删除等操作实例
-
php 连接 access数据库与修改 删除 增加 数据实例_PHP教程