🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Create a new table

#2320
From: Viatcheslav V. Vassiliev
Date: Tue, 19 Aug 2003 10:19
101 lines
4106 bytes
In BCB6 this looks as:

#include <ADODB_tlb.h>
#include <ADOX_tlb.h>

void __fastcall TForm1::Button1Click(TObject *Sender)
{
 //Database file
 WideString db = "C:\\Temp\\Test.mdb";
    if (FileExists(db)) DeleteFile(db);

 //Connection string
 WideString strConn = WideString("Provider=Microsoft.Jet.OLEDB.4.0;") +
  WideString("Data Source=") + db;

 {
  //Create database
  CatalogPtr cat = CoCatalog::Create();
  cat->Create(strConn);
 }

 //Open connection
 ConnectionPtr conn = CoConnection::Create();
 conn->Open(strConn.c_bstr(), WideString("").c_bstr(),
WideString("").c_bstr(), -1);

 tagVARIANT RecAffected;
 RecAffected.vt = VT_I4;
 RecAffected.intVal = 0;

 //Create table - here you can execute any SQL command
 conn->Execute(WideString("Create table [MyTable] ([Col1] Int Primary Key,
[Col2] VarChar(15))").c_bstr(),
  &RecAffected, adExecuteNoRecords);
}

If you are using BCB5 - be sure to delete all functions with GhostMethod_ in
name from imported type libraries.

----------------------------------------------------------------
Regards,
Viatcheslav V. Vassiliev
http://www.oledbdirect.com
The fastest way to access MS SQL Server, MS Jet (MS Access)
and Interbase (through OLEDB) databases.

"Lee" <gobroski@elltel.net> �������/�������� � �������� ���������:
news:3f41bf11@newsgroups.borland.com...
> Hello,
>
> I see that this is exactly what I need, but I am unsure on how to
implement
> the code to get the results that I desire.
>
> Thank you for your help though...  At least I have a map, with a
> destination.
>
> Lee
>
>
> "Viatcheslav V. Vassiliev" <support@oledbdirect.com> wrote in message
> news:3f40a28b$1@newsgroups.borland.com...
> > You are using OleVariant to work with Com object and I prefere to use
> > imported type library. So I will show code in JScript - you should have
no
> > problems converting it to C++:
> >
> > //Database file
> > var db = "C:\\Temp\\Test.mdb";
> > //Connection string
> > var strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" +
> >  "Data Source=" + db;
> >
> > //Create database
> > var cat = new ActiveXObject("ADOX.Catalog");
> > cat.Create(strConn);
> > cat = null;
> >
> > //Open connection
> > var conn = new ActiveXObject("ADODB.Connection");
> > conn.Open(strConn, "", "", -1);
> >
> > //SQL DDL command returns no recordset, this will optimize execute
method
> > var adExecuteNoRecords = 0x80;
> >
> > //Create table - here you can execute any SQL command
> > conn.Execute("Create table [MyTable] ([Col1] Int Primary Key, [Col2]
> > VarChar(15))",
> >  null, adExecuteNoRecords);
> >
> > ----------------------------------------------------------------
> > Regards,
> > Viatcheslav V. Vassiliev
> > http://www.oledbdirect.com
> > The fastest way to access MS SQL Server, MS Jet (MS Access)
> > and Interbase (through OLEDB) databases.
> >
> >
>
>
Technical Details
Message-ID: <3f41f9ca$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!sn-xit-01!sn-xit-08!supernews.com!newsfeeds.sol.net!skynet.be!skynet.be!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <3f3fde36$1@newsgroups.borland.com> <3f407796$1@newsgroups.borland.com> <3f408401$1@newsgroups.borland.com> <3f40a28b$1@newsgroups.borland.com> <3f41bf11@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII
X-Google-Thread: 10698b,5ff793e5206e9a54
X-Google-Attributes: gid10698b,public
X-Google-ArrivalTime: 2003-08-19 03:40:42 PST
From: "Viatcheslav V. Vassiliev" <support@oledbdirect.com>
Newsgroups: borland.public.cppbuilder.database.ado
References: <3f3fde36$1@newsgroups.borland.com> <3f407796$1@newsgroups.borland.com> <3f408401$1@newsgroups.borland.com> <3f40a28b$1@newsgroups.borland.com> <3f41bf11@newsgroups.borland.com>
Subject: Re: Create a new table
Date: Tue, 19 Aug 2003 14:19:10 +0400
Lines: 103
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
NNTP-Posting-Host: 213.247.201.57
Message-ID: <3f41f9ca$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1061288394 213.247.201.57 (19 Aug 2003 03:19:54 -0700)
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!sn-xit-01!sn-xit-08!supernews.com!newsfeeds.sol.net!skynet.be!skynet.be!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail