1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include <ComObj.hpp>
#include "Ouvrir_Base_Vide.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
// ne pas oublier d'inclure #include <comobj.hpp>
Variant vADO;
AnsiString Filename = "C:\\Documents and Settings\\blondelle\\Mes documents\\BASES\\maBdd26.mdb";
if (FileExists(Filename.c_str()))
{
DeleteFile(Filename);
}
AnsiString provider = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" +Filename+";";
vADO = Variant::CreateObject("ADOX.Catalog");
vADO.OleFunction("create", provider.c_str());
// on connecte ADOConnection
ADOConnection1->ConnectionString = provider;
ADOConnection1->LoginPrompt = false;
ADOCommand1->Connection = ADOConnection1;
// on cree une table vide au Nom Essai
AnsiString nom_table = "CREATE TABLE Essai (VALEUR TEXT(50))";
ADOCommand1->CommandText = nom_table;
ADOCommand1->Execute();
// on cree les entetes de trois colonnes authorname, email, web dans une table au nom Authors
AnsiString nomTable_colonnes = "CREATE TABLE Authors (authorname TEXT(50),email TEXT(50),web TEXT(50))";
ADOCommand1->CommandText = nomTable_colonnes;
ADOCommand1->Execute();
// on cree une clef primaire dans la table Essai VALEUR contient la clef primaire
AnsiString clef = "CREATE INDEX idxPrimary ON Essai (VALEUR) WITH PRIMARY";
ADOCommand1->CommandText = clef;
ADOCommand1->Execute();
// on cree une clef primaire dans la table Authors authorname contient la clef primaire
AnsiString clef1 = "CREATE INDEX idxPrimary ON Authors (authorname) WITH PRIMARY";
ADOCommand1->CommandText = clef1;
ADOCommand1->Execute();
// ici erreur
// on cree une nouvelle table avec des paramettres
AnsiString parametres = "CREATE TABLE Applications (Name TEXT(50),Description TEXT(50),Author TEXT(50) CONSTRAINT idxauthor REFERENCES Authors (authorname), Type TEXT(50) CONSTRAINT idxtype REFERENCES Types (typename),[Size] FLOAT,Cost CURRENCY, DateUpl DATETIME, Picture LONGBINARY)";
ADOCommand1->CommandText = parametres;
ADOCommand1->Execute();
// en quittant on libere les Variant
vADO = Unassigned;
} |
Partager