Article View: borland.public.cppbuilder.database.ado
Article #1873Re: Linking Tables to an MSAccess Database in Code
From: Viatcheslav V. Vassiliev
Date: Mon, 26 Jan 2004 17:16
Date: Mon, 26 Jan 2004 17:16
121 lines
4919 bytes
4919 bytes
1. cat->Tables->Append(Variant(thisTbl));
Why do you add thisTbl - it is a string. You create TCOM_Table object, fill
properties and do not use it. Add
tbl->set_Name(WideString(thisTbl).c_bstr());
after
tbl->ParentCatalog = cat;
and add table as
cat->Tables->Append(Variant((IDispatch*)tbl));
2. Change all strings to WideString - Variant accepts ANSI strings, COM does
not.
Your code should be:
AnsiString thisDb = "C:\\data\\HitTemp.mdb";
AnsiString thisTbl = "HitDataLinkTest";
AnsiString thatDb = "C:\\data\\HitData.mdb";
AnsiString thatTbl = "LinkTest";
DeleteFile(thisDb);
Variant thisDbConnectStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
+ thisDb;
Adox_tlb::TCOM_Catalog cat = CoCatalog::Create();
cat->Create(WideString(thisDbConnectStr));
// cat->set_ActiveConnection(thisDbConnectStr);
Adox_tlb::TCOM_Table tbl = CoTable::Create();
tbl->ParentCatalog = cat;
tbl->set_Name(WideString(thisTbl).c_bstr());
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 = WideString(thatDb);
ppvObject = tbl->Properties->get_Item(ppvName);
ppvObject->set_Value(ppvValue);
ppvName = WideString("Jet OLEDB:Remote Table Name");
ppvValue = WideString(thatTbl);
ppvObject = tbl->Properties->get_Item(ppvName);
ppvObject->set_Value(ppvValue);
// cat->Tables->Append(Variant(thisTbl));
cat->Tables->Append(Variant((IDispatch*)tbl));
cat.Release();
//------------------------------------------
Regards,
Vassiliev V. V.
http://www.managed-vcl.com - using .Net objects in Delphi + ADO.Net
http://www.oledbdirect.com - The fastest way to access MS SQL Server,
MS Jet (Access) and Interbase (through OLEDB)
"Robert Emmons" <remmons@aurigen.com> ???????/???????? ? ???????? ?????????:
news:vkda10dt31enmokkrfrgmipag5du0igvs4@4ax.com...
> Now all the code compiles and runs without error messages. However,
> it does not create a table in HitTemp.mdb linked to the "LinkTest"
> table in HitData.mdb. I suspect the problem is with the
> cat->Append(Variant) statement. I don't know what to use as the
> "Variant" or "tagVARIANT" argument.
>
> As usual, I would appreciate any help. Here is the code:
>
>
> AnsiString thisDb = "C:\\data\\HitTemp.mdb";
> AnsiString thisTbl = "HitDataLinkTest";
> AnsiString thatDb = "C:\\data\\HitData.mdb";
> AnsiString thatTbl = "LinkTest";
>
> Variant thisDbConnectStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data
> Source=" + thisDb;
>
>
> Adox_tlb::TCOM_Catalog cat = CoCatalog::Create();
> // cat->Create(WideString(thisDbConnectStr));
> cat->set_ActiveConnection(thisDbConnectStr);
>
> Adox_tlb::TCOM_Table tbl = CoTable::Create();
> tbl->ParentCatalog = cat;
>
>
> Adox_tlb::Property *ppvObject;
> Variant ppvName;
> Variant ppvValue;
>
> ppvName = "Jet OLEDB:Create Link";
> ppvValue = true;
> ppvObject = tbl->Properties->get_Item(ppvName);
> ppvObject->set_Value(ppvValue);
>
> ppvName = "Jet OLEDB:Link Datasource";
> ppvValue = thatDb;
> ppvObject = tbl->Properties->get_Item(ppvName);
> ppvObject->set_Value(ppvValue);
>
> ppvName = "Jet OLEDB:Remote Table Name";
> ppvValue = thatTbl;
> ppvObject = tbl->Properties->get_Item(ppvName);
> ppvObject->set_Value(ppvValue);
>
> cat->Tables->Append(Variant(thisTbl));
>
>
Technical Details
Message-ID:
<40154b9d$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!eusc.inter.net!npeer.de.kpn-eurorings.net!news.netcologne.de!newsfeed.netcologne.de!newshosting.com!news-xfer1.atl.newshosting.com!203.109.252.33.MISMATCH!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>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 09:20:13 PST From: "Viatcheslav V. Vassiliev" <support@oledbdirect.com> Newsgroups: borland.public.cppbuilder.database.ado References: <pu5t00drncdrn41hnftvesb6nviv7pjs4l@4ax.com> <400fcfe1@newsgroups.borland.com> <8ek510h1jdvdgubdq1gevn5kn0ka595vef@4ax.com> <4013952a@newsgroups.borland.com> <vkda10dt31enmokkrfrgmipag5du0igvs4@4ax.com> Subject: Re: Linking Tables to an MSAccess Database in Code Date: Mon, 26 Jan 2004 20:16:54 +0300 Lines: 123 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 NNTP-Posting-Host: 213.234.218.42 Message-ID: <40154b9d$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1075137437 213.234.218.42 (26 Jan 2004 09:17:17 -0700) Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!eusc.inter.net!npeer.de.kpn-eurorings.net!news.netcologne.de!newsfeed.netcologne.de!newshosting.com!news-xfer1.atl.newshosting.com!203.109.252.33.MISMATCH!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail