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

Thread: SQL statement ?

  1. #1
    Join Date
    Jun 2002
    Location
    India,bangalore
    Posts
    295

    Smile SQL statement ?

    hi there,

    I want to get all the table names in MS access.
    So what will be SQL statement ?

    thanks ahead
    rajeev

  2. #2
    Join Date
    Feb 2004
    Posts
    82
    Unfortunately, It seems no SQL statement can do this work. I am also looking for some time
    So, my way is to create a root table first containing all the table names in this database. then you can access any table by read this table.

  3. #3
    Join Date
    Aug 2002
    Location
    Landen, Belgium
    Posts
    86
    Do you use DAO ?

    if yes, this snippet of code did the trick for me:

    database.Open("dbase.mdb");

    int iRecords = 0;
    int iTotTables = database.GetTableDefCount();
    CDaoTableDefInfo tInfo;
    CDaoTableDef tb(&database);

    int iCount = 0;
    for (int n = 0; n < iTotTables; n++)
    {
    database.GetTableDefInfo(n, tInfo);
    LONG attr = tInfo.m_lAttributes;

    tb.Open(tInfo.m_strName);
    LONG CheckSysObj = tb.GetAttributes();

    if((CheckSysObj & dbSystemObject) == 0 && (attr & dbHiddenObject) != dbHiddenObject)
    {
    try
    {
    iRecords = tb.GetRecordCount();
    //display tablenames
    AfxMessageBox(tInfo.m_strName);
    }
    catch(CDaoException &e)
    {
    e.ReportError();
    }
    }
    tb.Close();
    }
    database.Close();

  4. #4
    Join Date
    Jun 2002
    Location
    India,bangalore
    Posts
    295
    hi broesli ,

    Your code works just fine. thank you very much.

    regards
    rajeev

  5. #5
    Join Date
    May 2004
    Location
    Germany
    Posts
    655
    or if you use ADO:

    you can get a recordset with information about all tables with the OpenSchema Method of the Connection object

    read this:
    http://msdn.microsoft.com/library/de...openschema.asp

    there are also examples for vc++, vj++ and vb

  6. #6
    Join Date
    Aug 2002
    Location
    Landen, Belgium
    Posts
    86
    no problem,

    glad I could help!


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