當前位置:首頁 » 密碼管理 » 通用資料庫訪問

通用資料庫訪問

發布時間: 2025-01-05 06:42:33

Ⅰ DBFactory一個通用的資料庫操作類,可以訪問SQL,Oracle資料庫。

Public Function ConnectionString(ByVal ProviderName As String) As String
Dim ConnStr As String = ""
Select Case ProviderName
Case "System.Data.OleDb"
ConnStr = "Provider=SQLOLEDB;Server=" & My.Settings.ServerName & ";Database=" & My.Settings.DBName & ";UID=" & My.Settings.DBUser & ";PWD=" & My.Settings.DBPWD
Case "System.Data.SqlClient"
ConnStr = "Data Source=" & My.Settings.ServerName & ";Initial Catalog=" & My.Settings.DBName & ";Persist Security Info=True;User ID=" & My.Settings.DBUser & ";Password=" & My.Settings.DBPWD
Case "System.Data.OracleClient"
ConnStr = "Data Source=" & My.Settings.ServerName & ";Password=" & My.Settings.DBPWD & ";User ID=" & My.Settings.DBUser
End Select
Return ConnStr
End Function
Public Function GetData(ByVal SqlString As String) As DataTable
Try
Dim mProvider As DbProviderFactory = DbProviderFactories.GetFactory(My.Settings.Provider)
Dim mConnection As DbConnection = mProvider.CreateConnection
mConnection.ConnectionString = ConnectionString(My.Settings.Provider)
Dim mCmd As DbCommand = mProvider.CreateCommand
mCmd.CommandText = SqlString
mCmd.Connection = mConnection
Dim mAda As DbDataAdapter = mProvider.CreateDataAdapter
mAda.TableMappings.Add("table", "temp")
mAda.SelectCommand = mCmd
mConnection.Open()
mCmd.ExecuteNonQuery()
mConnection.Close()
Dim dst As New DataSet
mAda.Fill(dst, "temp")
Return dst.Tables("temp")
Catch ex As Exception
Return New DataTable
End Try
End Function

熱點內容
清華編譯原理第2版答案pdf 發布:2025-01-07 04:48:03 瀏覽:935
pythonweb框架對比 發布:2025-01-07 04:48:00 瀏覽:605
交叉編譯應用程序示例 發布:2025-01-07 04:47:59 瀏覽:648
華為t系列存儲 發布:2025-01-07 04:36:40 瀏覽:908
大話西遊2文件夾 發布:2025-01-07 04:35:18 瀏覽:720
編譯的三個子過程 發布:2025-01-07 04:17:44 瀏覽:759
我的世界生存伺服器招收管理員 發布:2025-01-07 04:12:31 瀏覽:457
稅務ukey連不上伺服器是什麼原因 發布:2025-01-07 04:11:01 瀏覽:536
我的世界免費伺服器ip地址java 發布:2025-01-07 03:59:26 瀏覽:774
怎麼把安卓轉移到蘋果 發布:2025-01-07 03:47:02 瀏覽:270