Article View: borland.public.cppbuilder.database.ado
Article #2728Re: How can I create Access table?
From: Vladimir Afanasyev
Date: Tue, 25 Mar 2003 16:21
Date: Tue, 25 Mar 2003 16:21
58 lines
2332 bytes
2332 bytes
Hi,
"guba" <admin@coka.co.yu> wrote:
>How can I create Access table?
Next sample creates new Access database (c:/new.md) and
adds new table (MyTable) in this database:
(Some additional try, catch preferable)
void __fastcall TForm1::Button1Click(TObject *Sender)
{
#define adVarWChar 202
#define adInteger 3
Variant Catalog;
Variant Table;
Variant TablesDataBase;
Variant Columns;
if(FileExists("C://New.mdb"))
{
ShowMessage("Database exist");
Application->Terminate();
return;
}
Catalog=Variant::CreateObject("ADOX.Catalog");
Table=Variant::CreateObject("ADOX.Table");
try{
Catalog.Exec(Function("Create") << "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C://New.mdb;");
}
catch(...)
{
//problems - may be database already exist
}
//Creating table
Table.Exec(PropertySet("Name") << "MyTable");
Columns=Table.Exec(PropertyGet("Columns"));
Columns.Exec(Function("Append") << "ItsFirstField" << adVarWChar << 20);
Columns.Exec(Function("Append") << "Next" << adInteger);
//add table in database:
TablesDataBase=Catalog.Exec(PropertyGet("Tables"));
TablesDataBase.Exec(Function("Append") << Table);
TablesDataBase=Unassigned;
Columns=Unassigned;
Table=Unassigned;
Catalog=Unassigned;
}
Vladimir.
Technical Details
Message-ID:
<3e808207$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-03!sn-xit-01!sn-xit-09!supernews.com!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.fjserv.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<3e804d72@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10698b,1c113bcee69b4125 X-Google-Attributes: gid10698b,public X-Google-ArrivalTime: 2003-03-25 08:40:32 PST From: "Vladimir Afanasyev" <avv@systema.kiev.ua> Sender: "Vladimir Afanasyev" <avv@systema.kiev.ua> Reply-To: "Vladimir Afanasyev" <avv@systema.kiev.ua> Subject: Re: How can I create Access table? Newsgroups: borland.public.cppbuilder.database.ado X-User-Info: 62.244.14.114 62.244.14.114 X-Forwarded-For: 192.168.0.147 References: <3e804d72@newsgroups.borland.com> NNTP-Posting-Host: 207.105.83.65 Message-ID: <3e808207$1@newsgroups.borland.com> Date: 25 Mar 2003 08:21:27 -0800 X-Trace: newsgroups.borland.com 1048609287 207.105.83.65 (25 Mar 2003 08:21:27 -0800) Lines: 58 Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-03!sn-xit-01!sn-xit-09!supernews.com!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.fjserv.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail