国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

asp.net連接數據庫 增加,修改,刪除,查詢代碼

2024-07-10 13:19:35
字體:
來源:轉載
供稿:網友

復制代碼 代碼如下:


'數據庫連接
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

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 永川市| 梁平县| 竹溪县| 修水县| 武隆县| 南和县| 北流市| 民权县| 淮南市| 仪征市| 灌南县| 灵寿县| 安塞县| 聂荣县| 田林县| 仁化县| 读书| 安仁县| 宝应县| 枣阳市| 威远县| 临夏市| 闸北区| 清涧县| 广东省| 兰州市| 宣汉县| 九龙城区| 六盘水市| 新和县| 会理县| 镇平县| 司法| 西吉县| 天等县| 巍山| 修武县| 大竹县| 巴塘县| 湘阴县| 茌平县|