asp.net連接數(shù)據(jù)庫 增加,修改,刪除,查詢代碼
更新時間:2009年07月13日 21:19:35 作者:
asp.net連接數(shù)據(jù)庫,實現(xiàn)增加,修改,刪除,查詢的四大功能完整代碼。
復(fù)制代碼 代碼如下:
'數(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)文章
Asp.net中Response.Charset與Response.ContentEncoding區(qū)別示例分析
這篇文章主要介紹了Asp.net中Response.Charset與Response.ContentEncoding區(qū)別示例分析,對于深入理解Asp.net程序設(shè)計有一定的幫助,需要的朋友可以參考下2014-08-08ASP.NET插件uploadify批量上傳文件完整使用教程
這篇文章主要為大家詳細(xì)介紹了ASP.NET插件uploadify批量上傳文件完整使用教程,感興趣的小伙伴們可以參考一下2016-07-07ASP.NET實現(xiàn)License Key輸入功能的小例子
當(dāng)我們安裝微軟的軟件,多數(shù)軟件是需要輸入license key。它有五個文本框,輸入完第一個文本框之后,光標(biāo)自動跳至下一個文本框。 Insus.NET今天也使用asp.net來模仿一個。呵呵。2013-03-03ASP.NET中防止頁面刷新造成表單重復(fù)提交執(zhí)行兩次操作
本文主要介紹在Session存儲唯一標(biāo)識Token,通過和后臺對比,以實現(xiàn)防止刷新提交表單的問題。2016-04-04