asp.net連接數(shù)據(jù)庫 增加,修改,刪除,查詢代碼
更新時間:2009年07月13日 21:19:35 作者:
asp.net連接數(shù)據(jù)庫,實現(xiàn)增加,修改,刪除,查詢的四大功能完整代碼。
復制代碼 代碼如下:
'數(shù)據(jù)庫連接
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
'數(shù)據(jù)操作執(zhí)行
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
'數(shù)據(jù)更新
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() '關(guān)閉連接
End Try
End Sub
您可能感興趣的文章:
- ASP.NET web.config中數(shù)據(jù)庫連接字符串connectionStrings節(jié)的配置方法
- asp.net連接查詢SQL數(shù)據(jù)庫并把結(jié)果顯示在網(wǎng)頁上(2種方法)
- ASP.NET 6種常用數(shù)據(jù)庫的連接方法
- ASP.NET2.0 SQL Server數(shù)據(jù)庫連接詳解
- ASP.NET連接數(shù)據(jù)庫并獲取數(shù)據(jù)方法總結(jié)
- ASP.NET連接MySql數(shù)據(jù)庫的2個方法及示例
- ASP.NET中操作SQL數(shù)據(jù)庫(連接字符串的配置及獲取)
- ASP.NET 連接ACCESS數(shù)據(jù)庫的簡單方法
- ASP.NET連接 Access數(shù)據(jù)庫的幾種方法
- ASP.NET WebAPI連接數(shù)據(jù)庫的方法
相關(guān)文章
Server.Transfer,Response.Redirect的區(qū)別
Server.Transfer,Response.Redirect的區(qū)別...2006-12-12
asp.net 通過UserAgent判斷智能設(shè)備(Android,IOS)
搜集了比較全的 智能設(shè)備 的 Agent,然后又寫了程序,需要的朋友可以參考下2011-10-10
asp.net代碼中修改web.config節(jié)點的具體方法
在有些情況下,要在代碼中讀取一種全局變量,把這種全局變量放在web.config是一種常見的手段。2013-06-06
ASP.NET MVC中使用log4net的實現(xiàn)示例
這篇文章主要介紹了ASP.NET MVC中使用log4net的實現(xiàn)示例,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2020-01-01
Asp.net 中使用GridView控件實現(xiàn)Checkbox單選
在GridView控件中,第0列有放一個CheckBox控件,現(xiàn)想實現(xiàn)對CheckBox進行單選,怎么實現(xiàn)呢?下面小編通過本文給大家分享Asp.net 中使用GridView控件實現(xiàn)Checkbox單選功能,一起看看吧2017-07-07
asp.net core集成kindeditor實現(xiàn)圖片上傳功能
這篇文章主要為大家詳細介紹了asp.net core集成kindeditor實現(xiàn)圖片上傳功能,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2016-11-11

