Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


Show Recent Changes
Subscribe (RSS)
Misc. Pages
Comments
FAQ
Helpful Tools
Playground
Suggested Reading
Website TODO List
Download Visual Studio Add-In

SQLTables (odbc32)
 
.
Summary
Returns the list of table names stored in a specific data source.

C# Signature:

    [DllImport("odbc32.dll",CharSet=CharSet.Ansi)]
    static extern short SQLTables(IntPtr StatementHandle,
            string CatalogName, short NameLength1,
            string SchemaName,  short NameLength2,
            string TableName,   short NameLength3,
            string TableType,   short NameLength4);

VB Signature:

TODO.

User-Defined Types:

    // flags for null-terminated string
    const short SQL_NTS         = (-3);

    // FreeStmt() options
    const int  SQL_CLOSE        = 0;
    const int  SQL_DROP         = 1;
    const int  SQL_UNBIND       = 2;
    const int  SQL_RESET_PARAMS = 3;

Alternative Managed API:

ODBC ADO.NET does not support a database independent way to retrieve the tables in a database. That is probably the only excuse to be calling this ODBC C API.

Do you know one? Please contribute it!

Notes:

Resulting table has prefined columns:

    string table_cat   = cmd.GetFieldValue(1); //database name
    string table_schem = cmd.GetFieldValue(2); //table owner
    string table_name  = cmd.GetFieldValue(3); //table name
    string table_type  = cmd.GetFieldValue(4); //"TABLE","VIEW" or "SYNONYM"
    string remarks     = cmd.GetFieldValue(5);

Tips & Tricks:

Microsoft access ODBC driver only likes it if the first two parameters are NULL since the tablequalifier and tableowner don't apply to MDB files. Also, SYNONYMs are MSAccess linked tables.

Sample Code:

    void GetTables()
    {
        drop();
        if (!isOK(SQLAllocStmt(connectionHandle, out statementHandle)))
            throw new Exception("Failed to allocate statement.");
        if (!isOK(SQLTables(statementHandle,
            null,
            SQL_NTS,
            null,
            SQL_NTS,
            null,
            SQL_NTS,
            "TABLE,VIEW,SYNONYM",
            SQL_NTS)))
        {
            throw new Exception(GetError());
        }
    }

    void drop()
    {
        if (statementHandle.ToInt32()!=0)
        {
            SQLFreeStmt(statementHandle, SQL_DROP);
        }
        statementHandle = IntPtr.Zero;
    }

Documentation
SQLTables on MSDN

Please edit this page!

Do you have...

  • helpful tips or sample code to share for using this API in managed code?
  • corrections to the existing content?
  • variations of the signature you want to share?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).

 
Access PInvoke.net directly from VS:
Terms of Use
Edit This Page
Find References
Show Printable Version
Revisions