|
-
Feb 21st, 2002, 02:38 AM
#1
Thread Starter
Lively Member
code lines to change when converting from DAO to ADO?
hey,
i've been asking for help regarding the creation of a report from an SQL from a form, the steps i've gotten are used for ADO: myreport.datasource(). so i'm thinking about converting my DAO connection to ADO. i'm not using any data-controls, everything's in code. i was wondering, what DAO-specific lines must i alter? these are some of what i think are DAO codes in my program:
Set DB = OpenDatabase(App.Path & "\Members97.mdb")
Private DB As Database
Private RS As Recordset
Set RS = DB.OpenRecordset()
With RS
.Edit
.Fields("MemSName").Value = txtMemSName.Text
.Update
.Close
End With
anything else i should convert? how about the "project-references" properties?
do i need to put something like: ADODB.conection as a general declaration? also, are SQL statements the same in ADO?
-
Feb 21st, 2002, 04:12 AM
#2
Bouncy Member
you will need a reference to ADO in your project references.
ADO doesnt use database objects, it used Connections, Commands and Recordsets.
Also SQL should be the same for both.
-
Feb 21st, 2002, 04:35 AM
#3
Yeah, add the reference to "Microsoft ActiveX Data Objects x.0" object library, then use this :
Code:
Private conn As ADODB.Connection
Private RS As ADODB.Recordset
Set conn = ***
Set RS = "SELECT * FROM Table1", conn
The way you deal with the recordset object once at this point is much the same between ADO & DAO. The *** bit you can cheat on! 
1) Create a new txt file on your pc, then rename it to file.udl.
2) Open it up & set the options visually, then save it.
3) Rename the file back to a txt file & paste the created connection string into the above, voila !
-
Feb 21st, 2002, 04:40 AM
#4
Bouncy Member
-
Feb 21st, 2002, 04:46 AM
#5
I've been coding with ADO for a good 8 months & I'm sat here with 2 thick ADO books in front of me, considering the connection objects the main difference between DAO & ADO, you would have thought I'd have learn't this & wouldn't have to look it up all the time, but nooooo 
I still use that way as it's much lazier & easier
-
Feb 21st, 2002, 06:04 AM
#6
-
Feb 21st, 2002, 06:17 AM
#7
Thread Starter
Lively Member
????
thanks for your replies... i still don't get that *** part though. how does it work? what's it suppose to achieve? is the "non-cheat" way much more difficult?
-
Feb 21st, 2002, 06:21 AM
#8
It's letting you visually chose the options to build your querystring, which drivers to use, which locking the recordset should have etc.
If you look at the recordset object in the ADO help, then you can do it manually, but it's a lot more difficult ot understand & plan the options you want.
What part are you stuck with, how far have you got ?!?!
-
Feb 21st, 2002, 06:24 AM
#9
Bouncy Member
when you want to connect using ADO you have to declare a connection object and then specifiy a connectionstring before opening the connection.
One typo and it won't work, that's all. they're usually quite lengthy, so it's good if you don't have to remember the exact syntax etc.
this is an example of a connection string to connect to an Access database using Jet 4.0 anyway...
VB Code:
Dim cn as Connection
Set cn = New Connection
cn.ConnectionString = "Provider = Microsoft.Jet.OLEDB.4.0; " _
& "Data Source=[i]DATABASEPATH[/i];"
cn.Open
hope that helps
-
Feb 21st, 2002, 06:33 AM
#10
Fanatic Member
Alex,
Where did you pull that one from (the udl rename thing)???
Thats top that is!
That'll save me loads of time...
Beers on me!
thx
Crispin
VB6 ENT SP5
VB.NET
W2K ADV SVR SP3
WWW.BLOCKSOFT.CO.UK
[Microsoft Basic: 1976-2001, RIP]
-
Feb 21st, 2002, 06:38 AM
#11
-
Feb 21st, 2002, 07:29 AM
#12
Thread Starter
Lively Member
compile error: invalid outside procedure
(reference: Microsoft ActiveX Data Objects 2.0 Library)
(General declarations)
Private conn As ADODB.Connection
Private RS As ADODB.Recordset
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.3.51;Persist Security Info=False;Data Source=C:\Documents and Settings\Calvin Chong\My Documents\apiit\semester3\pp\coding\testado\Members97.mdb"
conn.Open
---------------------------------------------------------------
Private Sub cmdReport_Click()
Set RS = "SELECT * FROM Members ORDER BY MemNum"
DataReport1.DataSource = RS
DataReport1.Show
End Sub
what's wrong?
-
Feb 21st, 2002, 07:40 AM
#13
Frenzied Member
Originally posted by quipy
compile error: invalid outside procedure
(reference: Microsoft ActiveX Data Objects 2.0 Library)
(General declarations)
Private conn As ADODB.Connection
Private RS As ADODB.Recordset
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.3.51;Persist Security Info=False;Data Source=C:\Documents and Settings\Calvin Chong\My Documents\apiit\semester3\pp\coding\testado\Members97.mdb"
conn.Open
---------------------------------------------------------------
Private Sub cmdReport_Click()
Set RS = "SELECT * FROM Members ORDER BY MemNum"
DataReport1.DataSource = RS
DataReport1.Show
End Sub
what's wrong?
Where you tell to RS than conn is Rs connection ?
Do Datareport1 need a refresh ?
oh1mie/Vic

-
Feb 21st, 2002, 07:49 AM
#14
change that
Private Sub cmdReport_Click()
Set RS = "SELECT * FROM Members ORDER BY MemNum"
DataReport1.DataSource = RS
DataReport1.Show
End Sub
to:
dim rst as adodb.recordset
set rst = new adodb.recordset
rst.activeconnection = conn
rst.source = "SELECT * FROM Members ORDER BY MemNum"
rst.open
datareport1.datasource = rst
datareport1.show
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|