ado --模块 Public Conn As New ADODB.Connection Public rs As New ADODB.Recordset Public cmd As New ADODB.CommandPublic Function DBPath() As String DBPath = "Provider=MSDAORA.1;Password=密码;User ID=用户名;Data Source=数据库SID;Persist Security Info=True" End Function --界面: Private Sub Form_Load() On Error GoTo Err Dim ConnStr As String '字符串 ConnStr = DBPath With Conn .ConnectionString = ConnStr .ConnectionTimeout = 10 .CursorLocation = adUseClient .Open End With Set cmd.ActiveConnection = Conn cmd.CommandText = "select * from t_User" rs.CursorLocation = adUseClient rs.Open cmd, , adOpenStatic, adLockBatchOptimistic rs.MoveFirst Exit Sub Err: MsgBox ("连接数据库失败!") End End Sub
--模块
Public Conn As New ADODB.Connection
Public rs As New ADODB.Recordset
Public cmd As New ADODB.CommandPublic Function DBPath() As String
DBPath = "Provider=MSDAORA.1;Password=密码;User ID=用户名;Data Source=数据库SID;Persist Security Info=True"
End Function
--界面:
Private Sub Form_Load()
On Error GoTo Err
Dim ConnStr As String '字符串
ConnStr = DBPath
With Conn
.ConnectionString = ConnStr
.ConnectionTimeout = 10
.CursorLocation = adUseClient
.Open
End With
Set cmd.ActiveConnection = Conn
cmd.CommandText = "select * from t_User"
rs.CursorLocation = adUseClient
rs.Open cmd, , adOpenStatic, adLockBatchOptimistic
rs.MoveFirst
Exit Sub
Err:
MsgBox ("连接数据库失败!")
End
End Sub