Obtain the names of all tables in the ACCESS2000 Database

Source: Internet
Author: User
Obtain the names of all tables in the ACCESS2000 Database

Obtain the names of all tables in the ACCESS2000 Database


Void OpenSchemaX (TCHAR * TableName)
{
HRESULT hr = S_ OK;

: CoInitialize (NULL); // initialize Com

IADORecordBinding * picRs = NULL;

_ RecordsetPtr pRstSchema ("ADODB. Recordset ");
_ ConnectionPtr pConnection ("ADODB. Connection ");

PConnection-> ConnectionString = TableName;
PConnection-> Provider = "Microsoft. Jet. OLEDB.4.0 ";

Try
{
PConnection-> Open (pConnection-> ConnectionString, "", "", adModeUnknown );
PRstSchema-> QueryInterface (
_ Uuidof (IADORecordBinding), (LPVOID *) & picRs );

PRstSchema = pConnection-> OpenSchema (adSchemaTables); // process the name of the enumerated table

While (! (PRstSchema-> EndOfFile ))
{
CString strTableType;

_ Bstr_t table_name = pRstSchema-> Fields->
GetItem ("TABLE_NAME")-> Value; // obtain the table name

_ Bstr_t table_type = pRstSchema-> Fields->
GetItem ("TABLE_TYPE")-> Value; // obtain the table Type

StrTableType. Format ("% s", (LPCSTR) table_type );

If (! Lstrcmp (strTableType, _ T ("TABLE ")))
{
M_strList.AddString (LPCSTR) table_name); // Add the table name.
}

PRstSchema-> MoveNext ();
}
// Clean up objects before exit.

PRstSchema-> Close ();
PConnection-> Close ();
}

Catch (_ com_error & e)
{
// Configure y the user of errors if any.
// Pass a connection pointer accessed from the Connection.
PrintProviderError (pConnection );
PrintComError (e );
}
CoUninitialize ();
}

Void PrintProviderError (_ ConnectionPtr pConnection)
{
ErrorPtr pErr = NULL;

If (pConnection-> Errors-> Count)> 0)
{
Long nCount = pConnection-> Errors-> Count;
// Collection ranges from 0 to nCount-1.
For (long I = 0; I <nCount; I ++)
{
PErr = pConnection-> Errors-> GetItem (I );
CString strError;
StrError. Format ("Error number: % x \ t % s", pErr-> Number, pErr-> Description );
AfxMessageBox (strError );
}
}
}

Void PrintComError (_ com_error & e)
{
_ Bstr_t bstrSource (e. Source ());
_ Bstr_t bstrDescription (e. Description ());

// Print COM errors.
CString strError;
StrError. Format ("Error number: Description = % s \ tCode meaning = % s", (LPCSTR) bstrDescription, e. ErrorMessage ());
AfxMessageBox (strError );
}

Call method:

CString strFileName;
TCHAR FileName [MAX_PATH];
TCHAR bigBuff [2048] = _ T (""); // maximum common dialog buffer size
TCHAR szFilter [] = _ T ("Text Files (*. mdb) | *. mdb | All Files (*. *) | *.*
");
CFileDialog dlg (TRUE, NULL, NULL,
OFN_HIDEREADONLY | OFN_ALLOWMULTISELECT, szFilter );

// Modify OPENFILENAME members directly to point to bigBuff
Dlg. m_ofn.lpstrFile = bigBuff;
Dlg. m_ofn.nMaxFile = sizeof (bigBuff );

If (IDOK = dlg. DoModal ())
{
StrFileName = dlg. GetPathName ();
Lstrcpy (FileName, strFileName );
OpenSchemaX (FileName );
} (Source: fengshangwang road College)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.