CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: ADO

  1. #1
    Join Date
    Aug 1999
    Posts
    14

    ADO

    Hi,

    I want to connect to "MyDatabase.mdb", which has 3 tables: employees,
    sales,and purchases. I've got to hardcode the name of the table "employees" to open the table.
    Is there anyway to get how many tables are there in MyDatabase as well as
    the names of all the tables ? Thanks



    Set cnnData = New ADODB.Connection
    Set cmdData = New ADODB.Command
    Set rsData = New ADODB.Recordset


    strCnn = "..."

    cnnData.DefaultDatabase = "MyDatabase"
    cnnData.ConnectionString = strCnn
    cnnData.ConnectionTimeout = 30
    cnnData.Open strCnn
    rsData.CursorLocation = adUseServer
    rsData.LockType = adLockReadOnly


    rsData.Open "employees", cnnData, , , adCmdTable



  2. #2
    Join Date
    Apr 1999
    Posts
    49

    Re: ADO

    You can use the OpenSchema method of the connection object

    Dim rs = CreateObject("ADODB.Recordset")
    Dim cn = CreateObject("ADODB.Connection")

    'open the connection
    ...

    Set rs = cn.OpenSchema(adSchemaTables);

    Now, with the RecordCount property of the recordset, you know the number of tables.
    If you want to know the name of all the tables :

    While Not rs.EOF
    MsgBox rs("TABLE_NAME")
    rs.MoveNext
    Wend


    That's it.

    Marc


  3. #3
    Join Date
    Aug 1999
    Posts
    14

    Re: ADO

    Hi Marc,
    The answer is really cool. Thanks alot for that.


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

Featured