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

