🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.database.ado
Article #3295

Examples using ADOX imported typelib

#3295
From: Bill W
Date: Thu, 17 Oct 2002 13:10
111 lines
4665 bytes
For anyone who has been banging their head against a desk looking for an
answer to using ADOX in CBuilder, here are some solid examples.  This
example code demonstrates:
1) Creating a New Access MDB.
2) Creating new tables and columns.
3) Working with Jet Specific Table Properties
4) Creating Linked Tables in Access thru ADO

Note:
In order to use this code in cb you will have to import the ADOX type lib
To do so goto Project->Import Type Library->and choose ADO Ext. 2.5 or 2.6
for DDL and Security.

Once you have done this you now have a useable type library for ADOX
available in CB.

Now here's the code.  I hope this helps.  :^)

bool __fastcall TForm1::CreateMDB(AnsiString FileName)
{
    TCOM_Catalog XCatalog;
    WideString ConnectString;

    try
    {
        XCatalog = CoCatalog::Create();
        ConnectString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" +
WideString(FileName);
        XCatalog->Create((BSTR)ConnectString);
        if (FileExists(FileName))
        {
            return true;
        }
        else
        {
            return false;
        }
    }
    catch(Exception &error)
    {
        ShowMessage(error.Message.c_str());
        return false;
    }
}
//--------------------------------------------------------------------------
-
bool __fastcall TForm1::AppendTable(AnsiString FileName)
{
    TCOM_Catalog XCatalog;
    WideString ConnectString;
    WideString TableName;
    TCOM_Table XTable;

    try
    {
        XCatalog = CoCatalog::Create();
        ConnectString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" +
WideString(FileName);
        XCatalog->set_ActiveConnection((BSTR)ConnectString);
        TableName = "TestTable";
        XTable = CoTable::Create();
        XTable->set_Name((BSTR)TableName);
        XTable->Columns->Append("Col1", adInteger, 0);
        XTable->Columns->Append("Col2", adBoolean, 0);
        XCatalog->Tables->Append((IUnknown*)XTable);
        return true;
    }
    catch(Exception &error)
    {
        ShowMessage(error.Message.c_str());
        return false;
    }
}
//--------------------------------------------------------------------------
-
bool __fastcall TForm1::AppendLinkedTable(AnsiString
SourceFileName,AnsiString SourceTableName,AnsiString
DestinationFileName,AnsiString DestinationTableName)
{
    TCOM_Catalog XCatalog;
    WideString ConnectString;
    TCOM_Table XTable;

    try
    {
        XCatalog = CoCatalog::Create();
        ConnectString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" +
WideString(DestinationFileName);
        XCatalog->set_ActiveConnection((BSTR)ConnectString);
        XTable = CoTable::Create();
        XTable->set_ParentCatalog(XCatalog);
        XTable->set_Name((BSTR)WideString(DestinationTableName));
        XTable->Properties->get_Item((BSTR)WideString("Jet OLEDB:Link
Datasource"))->set_Value((BSTR)WideString(SourceFileName));
        XTable->Properties->get_Item((BSTR)WideString("Jet OLEDB:Link
Provider String"))->set_Value((BSTR)WideString("MS Access"));
        XTable->Properties->get_Item((BSTR)WideString("Jet OLEDB:Remote
Table Name"))->set_Value((BSTR)WideString(SourceTableName));
        XTable->Properties->get_Item((BSTR)WideString("Jet OLEDB:Create
Link"))->set_Value(Variant(true));
        XCatalog->Tables->Append((IUnknown*)XTable);
        return true;
    }
    catch(Exception &error)
    {
        ShowMessage(error.Message.c_str());
        return false;
    }
}
//--------------------------------------------------------------------------
-
Technical Details
Message-ID: <KEyr9.27347$nb.10749@nwrddc02.gnilink.net>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-03!sn-xit-06!sn-xit-08!supernews.com!newsfeed.news2me.com!cyclone1.gnilink.net!spamfinder.gnilink.net!nwrddc02.gnilink.net.POSTED!53ab2750!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10698b,d3855be8e71db886,start
X-Google-Attributes: gid10698b,public
X-Google-ArrivalTime: 2002-10-17 06:16:07 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-03!sn-xit-06!sn-xit-08!supernews.com!newsfeed.news2me.com!cyclone1.gnilink.net!spamfinder.gnilink.net!nwrddc02.gnilink.net.POSTED!53ab2750!not-for-mail
Reply-To: "Bill W" <bweiss@avar.net>
From: "Bill W" <bweiss@avar.net>
Newsgroups: borland.public.cppbuilder.database.ado
Subject: Examples using ADOX imported typelib
Lines: 118
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2600.0000
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000
Message-ID: <KEyr9.27347$nb.10749@nwrddc02.gnilink.net>
Date: Thu, 17 Oct 2002 13:10:02 GMT
NNTP-Posting-Host: 209.158.226.120
X-Complaints-To: abuse@verizon.net
X-Trace: nwrddc02.gnilink.net 1034860202 209.158.226.120 (Thu, 17 Oct 2002 09:10:02 EDT)
NNTP-Posting-Date: Thu, 17 Oct 2002 09:10:02 EDT