Article View: borland.public.cppbuilder.database.ado
Article #1876Re: Linking Tables to an MSAccess Database in Code
From: Robert Emmons
Date: Mon, 26 Jan 2004 19:10
Date: Mon, 26 Jan 2004 19:10
58 lines
2981 bytes
2981 bytes
On Mon, 26 Jan 2004 20:16:54 +0300, "Viatcheslav V. Vassiliev"
<support@oledbdirect.com> wrote:
>
> Various suggestions for linking tables between
> Access Databases
>
Success! Thanks again for your help and patience. I have pasted the
woking code below in case someone else needs it. Of course,
Viatcheslav V. Vassiliev deserves the credit for almost all of it.
I use "cat->set_ActiveConnection(thisDbConnectStr);", rather than
"DeleteFile()" and "Create()" because I am linking a table from an
existing MSAccess database into another existing MSAccess database.
Here is the code:
WideString thisDb = "C:\\data\\HitTemp.mdb";
WideString thisTbl = "HitDataLinkTest";
WideString thatDb = "C:\\data\\HitData.mdb";
WideString thatTbl = "LinkTest";
Variant thisDbConnectStr =
WideString("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + thisDb);
Adox_tlb::TCOM_Catalog cat = CoCatalog::Create();
// DeleteFile(thisDb);
// cat->Create(WideString(thisDbConnectStr));
cat->set_ActiveConnection(thisDbConnectStr);
Adox_tlb::TCOM_Table tbl = CoTable::Create();
tbl->set_Name(thisTbl.c_bstr());
tbl->ParentCatalog = cat;
Adox_tlb::Property *ppvObject;
Variant ppvName;
Variant ppvValue;
ppvName = WideString("Jet OLEDB:Create Link");
ppvValue = true;
ppvObject = tbl->Properties->get_Item(ppvName);
ppvObject->set_Value(ppvValue);
ppvName = WideString("Jet OLEDB:Link Datasource");
ppvValue = thatDb;
ppvObject = tbl->Properties->get_Item(ppvName);
ppvObject->set_Value(ppvValue);
ppvName = WideString("Jet OLEDB:Remote Table Name");
ppvValue = thatTbl;
ppvObject = tbl->Properties->get_Item(ppvName);
ppvObject->set_Value(ppvValue);
cat->Tables->Append(Variant((IDispatch*)tbl));
Technical Details
Message-ID:
<3bpa1093p2ksq3a93pb4jf7cfr372dmti1@4ax.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!nntp-relay.ihug.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailReferences:
<pu5t00drncdrn41hnftvesb6nviv7pjs4l@4ax.com> <400fcfe1@newsgroups.borland.com> <8ek510h1jdvdgubdq1gevn5kn0ka595vef@4ax.com> <4013952a@newsgroups.borland.com> <vkda10dt31enmokkrfrgmipag5du0igvs4@4ax.com> <40154b9d$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10698b,624e139e318cdbfb X-Google-Attributes: gid10698b,public X-Google-ArrivalTime: 2004-01-26 11:10:00 PST From: Robert Emmons <remmons@aurigen.com> Newsgroups: borland.public.cppbuilder.database.ado Subject: Re: Linking Tables to an MSAccess Database in Code Date: Mon, 26 Jan 2004 14:10:36 -0500 Message-ID: <3bpa1093p2ksq3a93pb4jf7cfr372dmti1@4ax.com> References: <pu5t00drncdrn41hnftvesb6nviv7pjs4l@4ax.com> <400fcfe1@newsgroups.borland.com> <8ek510h1jdvdgubdq1gevn5kn0ka595vef@4ax.com> <4013952a@newsgroups.borland.com> <vkda10dt31enmokkrfrgmipag5du0igvs4@4ax.com> <40154b9d$1@newsgroups.borland.com> X-Newsreader: Forte Agent 1.93/32.576 English (American) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 68.193.14.50 X-Trace: newsgroups.borland.com 1075144112 68.193.14.50 (26 Jan 2004 11:08:32 -0700) Lines: 59 Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!nntp-relay.ihug.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail