Hi,
I just wanted to know what is the difference between the two styles of database code:
Style 1:
Dim adoConnect As ADODB.Connection
Dim adoRecordset As ADODB.Recordset
Private Sub Form_Load()
Dim sql As String
Set adoConnect = New ADODB.Connection
adoConnect.Open "PROVIDER=Microsoft.jet.OLEDB.4.0;" _
& "Data Source=C:\mydb.mdb"
sql = "SELECT SetupTab.SetupName, CellTab.CellName "
sql = sql & "FROM SetupTab INNER JOIN CellTab ON SetupTab.CellID = CellTab.CellID;"
Set adoRecordset = New ADODB.Recordset
adoRecordset.Open sql, adoConnect, adOpenKeyset, adLockOptimistic
'sname and cname are two textboxes on the form
sname.Text = adoRecordset!SetupName
cname.Text = adoRecordset!CellName
End Sub
Second style:
Public Sub Form_Load()
Dim parameter1, parameter2, parameter3 As String
Dim adoconnect As Connection
Set adoconnect = New Connection
adoconnect.Open "PROVIDER=Microsoft.jet.OLEDB.4.0;" _
& "Data Source=C:\mydb.mdb;"
Set adoRecordset1 = New Recordset
parameter1 = "setuptab.setupname, celltab.Cellname"
parameter2 = "setuptab, celltab"
parameter3 = "setuptab.cellid = celltab.CellID"
adoRecordset1.Open "select " & parameter1 & " from " & parameter2 & " where " & parameter3 & " order by setupid", _
adoconnect, adOpenStatic, adLockOptimistic
'sname and cname are text boxes on the form
Set sname.DataSource = adoRecordset1
sname.DataField = "setupname"
Set cname.DataSource = adoRecordset1
cname.DataField = "cellname"
What im really asking in this question is what is the difference between defining a connection as "ADODB.connection" and just defining it as a "connection". Secondly, I was just wondering what the difference between using the two commands:
Set adoRecordset1 = New Recordset
Set sname.DataSource = adoRecordset1
sname.DataField = "setupname"
and
Set adoRecordset = New ADODB.Recordset
sname.Text = adoRecordset!SetupName
can anyone help me because this ado stuff is kind of confusing, thanks
I just wanted to know what is the difference between the two styles of database code:
Style 1:
Dim adoConnect As ADODB.Connection
Dim adoRecordset As ADODB.Recordset
Private Sub Form_Load()
Dim sql As String
Set adoConnect = New ADODB.Connection
adoConnect.Open "PROVIDER=Microsoft.jet.OLEDB.4.0;" _
& "Data Source=C:\mydb.mdb"
sql = "SELECT SetupTab.SetupName, CellTab.CellName "
sql = sql & "FROM SetupTab INNER JOIN CellTab ON SetupTab.CellID = CellTab.CellID;"
Set adoRecordset = New ADODB.Recordset
adoRecordset.Open sql, adoConnect, adOpenKeyset, adLockOptimistic
'sname and cname are two textboxes on the form
sname.Text = adoRecordset!SetupName
cname.Text = adoRecordset!CellName
End Sub
Second style:
Public Sub Form_Load()
Dim parameter1, parameter2, parameter3 As String
Dim adoconnect As Connection
Set adoconnect = New Connection
adoconnect.Open "PROVIDER=Microsoft.jet.OLEDB.4.0;" _
& "Data Source=C:\mydb.mdb;"
Set adoRecordset1 = New Recordset
parameter1 = "setuptab.setupname, celltab.Cellname"
parameter2 = "setuptab, celltab"
parameter3 = "setuptab.cellid = celltab.CellID"
adoRecordset1.Open "select " & parameter1 & " from " & parameter2 & " where " & parameter3 & " order by setupid", _
adoconnect, adOpenStatic, adLockOptimistic
'sname and cname are text boxes on the form
Set sname.DataSource = adoRecordset1
sname.DataField = "setupname"
Set cname.DataSource = adoRecordset1
cname.DataField = "cellname"
What im really asking in this question is what is the difference between defining a connection as "ADODB.connection" and just defining it as a "connection". Secondly, I was just wondering what the difference between using the two commands:
Set adoRecordset1 = New Recordset
Set sname.DataSource = adoRecordset1
sname.DataField = "setupname"
and
Set adoRecordset = New ADODB.Recordset
sname.Text = adoRecordset!SetupName
can anyone help me because this ado stuff is kind of confusing, thanks