Gets the names of all tables in the ACCESS2000 database _access

Source: Internet
Author: User

void Openschemax (TCHAR *tablename)
{
HRESULT hr = S_OK;

:: CoInitialize (NULL); Initializing 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);//enumeration table name handling

while (!) ( Prstschema->endoffile))
{
CString Strtabletype;

_bstr_t table_name = prstschema->fields->
GetItem ("table_name")->value;//get the name of the table

_bstr_t Table_type = prstschema->fields->
GetItem ("Table_type")->value;//gets the type of the table

Strtabletype.format ("%s", (LPCSTR) table_type);

if (!lstrcmp (strtabletype,_t ("TABLE"))
{
M_strlist.addstring ((LPCSTR) table_name);//Add the name of the table
}

Prstschema->movenext ();
}
Clean up objects before exit.

Prstschema->close ();
Pconnection->close ();
}

catch (_com_error &e)
{
Notify 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: Wind-flash Network 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.