Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How can I create Access table?

0 views
Skip to first unread message

guba

unread,
Mar 25, 2003, 5:42:22 AM3/25/03
to
How can I create Access table?


Vladimir Afanasyev

unread,
Mar 25, 2003, 11:21:27 AM3/25/03
to

Hi,

"guba" <ad...@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.

guba

unread,
Mar 26, 2003, 1:22:49 AM3/26/03
to
Helo Vladimir

Thank you the example, but I cant it run. The BCB 5 show me a few errors.


"Vladimir Afanasyev" <a...@systema.kiev.ua> wrote in message
news:3e808207$1...@newsgroups.borland.com...

Hi,

"guba" <ad...@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(...)
{

file://problems - may be database already exist
}


file://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);

file://add table in database:

Vladimir Afanasyev

unread,
Mar 26, 2003, 2:23:40 AM3/26/03
to

Hi,

"guba" <ad...@coka.co.yu> wrote:
>Helo Vladimir
>
>Thank you the example, but I cant it run. The BCB 5 show me a few errors.
>
>

I compiled that code on BCB5 and had no any error.
May be you send error description?
Vladimir.

guba

unread,
Mar 27, 2003, 5:47:13 AM3/27/03
to

"Vladimir Afanasyev" <a...@systema.kiev.ua> wrote in message
news:3e81557c$1...@newsgroups.borland.com...

Hi,


The error is "Multiple declaration for 'file' "


Vladimir Afanasyev

unread,
Mar 27, 2003, 12:41:28 PM3/27/03
to

"guba" <ad...@coka.co.yu> wrote:

>
>
>The error is "Multiple declaration for 'file' "

It sounds funny, there no any such variable...
I recompile code - it's work.
May be in the next month I create application (with various
possibility from ADO) for working with MS Access and put it
in the codecentral.
Vladimir.

Ivo Karindi

unread,
Mar 28, 2003, 5:14:40 AM3/28/03
to
I am wrestling with similar issues currently. Your example helps a lot
in getting things cleared up a bit. Are there any sources (books,
tutorials, etc) on the 'net where I could learn some more of this
stuff? I am mostly interested in manipulating and retrieving data from
a MS Access database from a DLL. I got your DB making example working
wonderfully from my DLL and would like to learn more of this stuff.

Thanks a lot for your help,

Ivo Karindi

"Vladimir Afanasyev" <a...@systema.kiev.ua> wrote in message

news:3e808207$1...@newsgroups.borland.com...

Steve

unread,
Mar 28, 2003, 5:52:15 AM3/28/03
to
> >The error is "Multiple declaration for 'file' "
>
> It sounds funny, there no any such variable...

Could it be the "file:" text that OE inserts when you write
a comment starting with a double slash?

file://this is a comment !!!!!!!!!!!!!!

Bye,

Steve.


Vladimir Afanasyev

unread,
Mar 28, 2003, 7:31:05 AM3/28/03
to
Hi Ivo,

"Ivo Karindi" <so...@ieslc.com> wrote:
>Are there any sources (books,
>tutorials, etc) on the 'net where I could learn some more of this
>stuff? I am mostly interested in manipulating and retrieving data from
>a MS Access database from a DLL. I got your DB making example working
>wonderfully from my DLL and would like to learn more of this stuff.

You know our main resource - Microsoft site.
The main info:

ADO Programmer's Guide
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ado270/htm/pg_introduction.asp

ADO Code Samples
http://msdn.microsoft.com/library/default.asp?url=/code/list/ado.asp?frame=true

Samples referenced to MSJ/MSDN online.

And search engine on Microsoft site:
http://www.microsoft.com/isapi/CTRedir.asp?type=CT&source=WWW&sPage=Search_Advanced|Search||Advanced%20Search&tPage=http://search.microsoft.com/advanced_search.asp?siteid=us

I suppose next reference will be very usefull for you:
Defining and Retrieving a Database's Schema
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndao/html/daotoadoupdate_topic6.asp

Regards,
Vladimir.

guba

unread,
Mar 28, 2003, 8:12:19 AM3/28/03
to
When I write "file://anything " , I can't compile the code. Error is
"Multiple declaration for 'file'"
But when I write "// file://anything" I can compile the code, but when I
click on Button1, the error is "The object referenced by the application no
longer points to a valid object."


"Steve" <steve_al...@SPAMhotmail.com> wrote in message
news:3e84...@newsgroups.borland.com...

Vladimir Afanasyev

unread,
Mar 28, 2003, 7:50:03 AM3/28/03
to

Hi Steve,

Thank you for explanation so he need only delete all
comments and "file:" before comments. It is browser problem.

I even wanted to send this sample in the attachment
group. But I use browser (because firewall) for access
to newsgroup. No possibility send file in attachment
group in this case.
I hope guba understand now.
Vladimir.


Vladimir Afanasyev

unread,
Mar 28, 2003, 8:46:56 AM3/28/03
to
Hi,

"guba" <ad...@coka.co.yu> wrote:
>When I write "file://anything " , I can't compile the code. Error is
>"Multiple declaration for 'file'"
>But when I write "// file://anything" I can compile the code, but when I
>click on Button1, the error is "The object referenced by the application no
>longer points to a valid object."
>

So zip your project and send it in the
borland.public.attachment for me or directly on my E-mail.

Vladimir.

Vladimir Afanasyev

unread,
Mar 31, 2003, 6:40:09 AM3/31/03
to

Yes,
It is really my error.

was:


Catalog.Exec(Function("Create") << "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C://New.mdb;");

should be:


Catalog.Exec(Function("Create") << "Provider=Microsoft.Jet.OLEDB.4.0;Data

Source=C:\\New.mdb;");

or

Catalog.Exec(Function("Create") << "Provider=Microsoft.Jet.OLEDB.4.0;Data

Source=C:/New.mdb;");
-----

was:
if(FileExists("C://New.mdb"))

Should be -
if(FileExists("C:\\New.mdb"))

or
if(FileExists("C:/New.mdb"))

Vladimir.


0 new messages