Public Conn As New ADODB.Connection '数据库连接 With Conn .ConnectionTimeout = 30 .CursorLocation = adUseClient .Provider = "SQLOLEDB.1" .Properties("Data Source").Value = sServerName .Properties("Initial Catalog").Value = sDatabaseName .Properties("User ID").Value = sUserId .Properties("Password").Value = sPassWord .Open End With
' ------------------------------------------------------------------------ ' Copyright ( C ) 1999 Jainil Infotech Inc. ' ' You have a royalty-free right to use, modify, reproduce and distribute ' the Sample Application Files (and/or any modified version) in any way ' you find useful, provided that you agree that Jainil Infotech Inc. has no warranty, ' obligations or liability for any Sample Application Files. ' Form Name: daoado ' Author : Bhavesh S. Patel ' Date : 12 / 07 / 1999 ' Description : ADO & DAO VB6 ' Email : [email protected] ' [email protected] ' ' ------------------------------------------------------------------------ Option Explicit 'Ado variables Dim adocon As Connection Dim rsado As Recordset 'Dao variables Dim daodb As DAO.Database Dim daors As DAO.Recordset Private Sub Form_Load() 'Ado Codeing Set adocon = New Connection adocon.CursorLocation = adUseClient adocon.Open "Provider=Microsoft.jet.OLeDB.3.51;Data Source=" & App.Path & "\adodao.mdb;" Set rsado = New Recordset rsado.Open "adodao", adocon, adOpenDynamic, adLockOptimistic If rsado.RecordCount > 0 Then rsado.MoveLast rsado.MoveFirst Text1.Text = rsado.Fields(0) End If 'Dao Codeing Set daodb = OpenDatabase(App.Path & "\adodao.mdb") Set daors = daodb.OpenRecordset("adodao", 2) If daors.RecordCount > 0 Then daors.MoveLast daors.MoveFirst Text2.Text = daors.Fields(0) End If End Sub
With Conn
.ConnectionTimeout = 30
.CursorLocation = adUseClient
.Provider = "SQLOLEDB.1"
.Properties("Data Source").Value = sServerName
.Properties("Initial Catalog").Value = sDatabaseName
.Properties("User ID").Value = sUserId
.Properties("Password").Value = sPassWord
.Open
End With
' Copyright ( C ) 1999 Jainil Infotech Inc.
'
' You have a royalty-free right to use, modify, reproduce and distribute
' the Sample Application Files (and/or any modified version) in any way
' you find useful, provided that you agree that Jainil Infotech Inc. has no warranty,
' obligations or liability for any Sample Application Files.
' Form Name: daoado
' Author : Bhavesh S. Patel
' Date : 12 / 07 / 1999
' Description : ADO & DAO VB6
' Email : [email protected]
' [email protected]
'
' ------------------------------------------------------------------------
Option Explicit
'Ado variables
Dim adocon As Connection
Dim rsado As Recordset
'Dao variables
Dim daodb As DAO.Database
Dim daors As DAO.Recordset
Private Sub Form_Load()
'Ado Codeing
Set adocon = New Connection
adocon.CursorLocation = adUseClient
adocon.Open "Provider=Microsoft.jet.OLeDB.3.51;Data Source=" & App.Path & "\adodao.mdb;"
Set rsado = New Recordset
rsado.Open "adodao", adocon, adOpenDynamic, adLockOptimistic
If rsado.RecordCount > 0 Then
rsado.MoveLast
rsado.MoveFirst
Text1.Text = rsado.Fields(0)
End If
'Dao Codeing
Set daodb = OpenDatabase(App.Path & "\adodao.mdb")
Set daors = daodb.OpenRecordset("adodao", 2)
If daors.RecordCount > 0 Then
daors.MoveLast
daors.MoveFirst
Text2.Text = daors.Fields(0)
End If
End Sub