当前位置:首页 » 密码管理 » 通用数据库访问

通用数据库访问

发布时间: 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