Results 1 to 14 of 14

Thread: code lines to change when converting from DAO to ADO?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2002
    Posts
    103

    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?

  2. #2
    Bouncy Member darre1's Avatar
    Join Date
    May 2001
    Location
    Peterborough, UK
    Posts
    3,828
    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.
    Confucious say, "Man standing naked in biscuit barrel not necessarily ****ing crackers."

    Don't forget to format your code in your posts

  3. #3
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538
    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 !

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  4. #4
    Bouncy Member darre1's Avatar
    Join Date
    May 2001
    Location
    Peterborough, UK
    Posts
    3,828

    Thumbs up

    Originally posted by alex_read
    ...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 !

    Great tip!!

    Confucious say, "Man standing naked in biscuit barrel not necessarily ****ing crackers."

    Don't forget to format your code in your posts

  5. #5
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538
    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

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  6. #6
    Bouncy Member darre1's Avatar
    Join Date
    May 2001
    Location
    Peterborough, UK
    Posts
    3,828
    i do something similar, i make a connection using the dataenvironment and then copy the connectionstring property

    your's is easier and lazier though woohoo!
    Confucious say, "Man standing naked in biscuit barrel not necessarily ****ing crackers."

    Don't forget to format your code in your posts

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Feb 2002
    Posts
    103

    ????

    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?

  8. #8
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538
    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 ?!?!

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  9. #9
    Bouncy Member darre1's Avatar
    Join Date
    May 2001
    Location
    Peterborough, UK
    Posts
    3,828
    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:
    1. Dim cn as Connection
    2.  
    3. Set cn = New Connection
    4.  
    5. cn.ConnectionString = "Provider = Microsoft.Jet.OLEDB.4.0; " _
    6.         & "Data Source=[i]DATABASEPATH[/i];"
    7. cn.Open

    hope that helps
    Confucious say, "Man standing naked in biscuit barrel not necessarily ****ing crackers."

    Don't forget to format your code in your posts

  10. #10
    Fanatic Member crispin's Avatar
    Join Date
    Aug 2000
    Location
    2 clicks west of a Quirkafleeg...Cornwall, England
    Posts
    754
    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]

  11. #11
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538
    Hmm, Cornwall, it'll take a couple of hours, but if it's a free pint then it's worth it

    I used to get a load of quizes through in Excel - sort of
    Name John Lennons 1980 No1 :
    where the answers'll be hidden - renaming files to txt files was a quick hacking technique When I first saw the UDL file I thought whyt not, it might work - renamed it & wayhay, lazy coding !!!

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  12. #12

    Thread Starter
    Lively Member
    Join Date
    Feb 2002
    Posts
    103
    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?

  13. #13
    Frenzied Member oh1mie's Avatar
    Join Date
    Sep 2001
    Location
    Finland
    Posts
    1,043
    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


  14. #14
    Helger
    Guest
    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
  •  



Click Here to Expand Forum to Full Width