2 个解决方案
#1
使用ADO.NET(注意不是ADO).
#2
Imports System.Data
Imports System.Data.oledb
Public Class cBase
Dim m_dbCnn As New OleDbConnection
'連接Oracle資料庫
Public Function ConnectOracle(ByVal pServer As String, ByVal pUid As String, ByVal pPwd As String) As OleDbConnection
Dim myCnn As New OleDbConnection
With myCnn
.ConnectionString = "Provider=MSDAORA.1;Password='" & pPwd & "';User ID='" & pUid & "';Data Source='" & pServer & "'"
Try
.Open()
Catch er As Exception
MsgBox(er.ToString)
End Try
End With
m_dbCnn = myCnn
Return myCnn
End Function
'連接SqlServer資料庫
Public Function ConnectSQLServer(ByVal pServer As String, ByVal pCatalog As String, ByVal pUid As String, ByVal pPwd As String) As OleDbConnection
Dim myCnn As New OleDbConnection
With myCnn
.ConnectionString = "Provider=SQLOLEDB.1;Initial Catalog = " & pCatalog & ";Data source = " & pServer & ";user id = " & pUid & ";password = " & pPwd
Try
.Open()
Catch er As Exception
MsgBox(er.ToString)
End Try
End With
m_dbCnn = myCnn
Return myCnn
End Function
End Class
Imports System.Data.oledb
Public Class cBase
Dim m_dbCnn As New OleDbConnection
'連接Oracle資料庫
Public Function ConnectOracle(ByVal pServer As String, ByVal pUid As String, ByVal pPwd As String) As OleDbConnection
Dim myCnn As New OleDbConnection
With myCnn
.ConnectionString = "Provider=MSDAORA.1;Password='" & pPwd & "';User ID='" & pUid & "';Data Source='" & pServer & "'"
Try
.Open()
Catch er As Exception
MsgBox(er.ToString)
End Try
End With
m_dbCnn = myCnn
Return myCnn
End Function
'連接SqlServer資料庫
Public Function ConnectSQLServer(ByVal pServer As String, ByVal pCatalog As String, ByVal pUid As String, ByVal pPwd As String) As OleDbConnection
Dim myCnn As New OleDbConnection
With myCnn
.ConnectionString = "Provider=SQLOLEDB.1;Initial Catalog = " & pCatalog & ";Data source = " & pServer & ";user id = " & pUid & ";password = " & pPwd
Try
.Open()
Catch er As Exception
MsgBox(er.ToString)
End Try
End With
m_dbCnn = myCnn
Return myCnn
End Function
End Class
#1
使用ADO.NET(注意不是ADO).
#2
Imports System.Data
Imports System.Data.oledb
Public Class cBase
Dim m_dbCnn As New OleDbConnection
'連接Oracle資料庫
Public Function ConnectOracle(ByVal pServer As String, ByVal pUid As String, ByVal pPwd As String) As OleDbConnection
Dim myCnn As New OleDbConnection
With myCnn
.ConnectionString = "Provider=MSDAORA.1;Password='" & pPwd & "';User ID='" & pUid & "';Data Source='" & pServer & "'"
Try
.Open()
Catch er As Exception
MsgBox(er.ToString)
End Try
End With
m_dbCnn = myCnn
Return myCnn
End Function
'連接SqlServer資料庫
Public Function ConnectSQLServer(ByVal pServer As String, ByVal pCatalog As String, ByVal pUid As String, ByVal pPwd As String) As OleDbConnection
Dim myCnn As New OleDbConnection
With myCnn
.ConnectionString = "Provider=SQLOLEDB.1;Initial Catalog = " & pCatalog & ";Data source = " & pServer & ";user id = " & pUid & ";password = " & pPwd
Try
.Open()
Catch er As Exception
MsgBox(er.ToString)
End Try
End With
m_dbCnn = myCnn
Return myCnn
End Function
End Class
Imports System.Data.oledb
Public Class cBase
Dim m_dbCnn As New OleDbConnection
'連接Oracle資料庫
Public Function ConnectOracle(ByVal pServer As String, ByVal pUid As String, ByVal pPwd As String) As OleDbConnection
Dim myCnn As New OleDbConnection
With myCnn
.ConnectionString = "Provider=MSDAORA.1;Password='" & pPwd & "';User ID='" & pUid & "';Data Source='" & pServer & "'"
Try
.Open()
Catch er As Exception
MsgBox(er.ToString)
End Try
End With
m_dbCnn = myCnn
Return myCnn
End Function
'連接SqlServer資料庫
Public Function ConnectSQLServer(ByVal pServer As String, ByVal pCatalog As String, ByVal pUid As String, ByVal pPwd As String) As OleDbConnection
Dim myCnn As New OleDbConnection
With myCnn
.ConnectionString = "Provider=SQLOLEDB.1;Initial Catalog = " & pCatalog & ";Data source = " & pServer & ";user id = " & pUid & ";password = " & pPwd
Try
.Open()
Catch er As Exception
MsgBox(er.ToString)
End Try
End With
m_dbCnn = myCnn
Return myCnn
End Function
End Class