Click to See Complete Forum and Search --> : How to retreive table name from SQL server database


reenacutie
February 25th, 2005, 03:18 AM
Can some1 plz tell me how to get table name and field name from SQL in MFC VC++
an ODBC connection is being used.

Davey
February 25th, 2005, 04:19 AM
Have a look at the following:

Get list of tables (http://www.hostingphpbb.com/forum/viewtopic.php?t=21&mforum=databasefaq)
Get columns in a table (http://www.hostingphpbb.com/forum/viewtopic.php?t=7&mforum=databasefaq)

Krzemo
February 25th, 2005, 04:39 AM
Use ODBC API for it:


// Get a list of all tables in the current database.
SQLTables(hstmt, NULL, 0, NULL, 0, NULL, 0, NULL,0);
// Get a list of all tables in all databases.
SQLTables(hstmt, (SQLCHAR*) "%", SQL_NTS, NULL, 0, NULL, 0, NULL,0);
// Get a list of databases on the current connection's server.
SQLTables(hstmt, (SQLCHAR*) "%", SQL_NTS, (SQLCHAR*)"", 0, (SQLCHAR*)"",
0, NULL, 0);

For list of columns use SQLColumns...

ODBC API is (should be) database independent.

Best regards,
Krzemo.