Hai Ly Hoang
Since you are dealing exclusively with Access, specifically with the Jet
database, then you should consider using the Jet extensions for ADO - aka
ADOX. You can create an instance of the Catalog object, then append a
table - after you have created a table object and appended the columns.
Here is a sample piece of code that I quickly threw together. It adds one
table to a newly created database, and in that table there is one autonumber
integer field (which is then given the Primary key attribute), and three
varchar fields. I hope it helps.
regards
roy fine
//
// ADOX_Create.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#import "c:\program files\common files\system\ado\msadox.dll"
/* ***********************************************************************
*/
void MakeDatabase()
{
::CoInitialize(NULL);
ADOX::_CatalogPtr cat(__uuidof(ADOX::Catalog));
cat->Create("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\\NewJet.mdb");
ADOX::_TablePtr tbl(__uuidof(ADOX::Table));
tbl->Name = _bstr_t("MyTable");
ADOX::_ColumnPtr col_CID(__uuidof(ADOX::Column));
col_CID->Name=_bstr_t(L"CID");
col_CID->put_Type(ADOX::adInteger);
col_CID->ParentCatalog = cat;
ADOX:

ropertiesPtr props = col_CID->GetProperties();
props->GetItem(L"AutoIncrement")->PutValue(_variant_t(true));
ADOX::_ColumnPtr col_FNAME(__uuidof(ADOX::Column));;
col_FNAME->Name=_bstr_t(L"FNAME");
col_FNAME->ParentCatalog = cat;
col_FNAME->put_Type(ADOX::adVarWChar);
col_FNAME->put_DefinedSize(32);
ADOX::_ColumnPtr col_LNAME(__uuidof(ADOX::Column));;
col_LNAME->Name=_bstr_t(L"LNAME");
col_LNAME->put_Type(ADOX::adVarWChar);
col_LNAME->put_DefinedSize(32);
ADOX::_ColumnPtr col_ADDRESS(__uuidof(ADOX::Column));;
col_ADDRESS->Name=_bstr_t(L"ADDRESS");
col_ADDRESS->put_Type(ADOX::adVarWChar);
col_ADDRESS->put_DefinedSize(66);
tbl->GetColumns()->Append(_variant_t(col_CID,true),ADOX::adInteger,0);
tbl->GetColumns()->Append(_variant_t(col_FNAME,true),ADOX::adVarWChar,32);
tbl->GetColumns()->Append(_variant_t(col_LNAME,true),ADOX::adVarChar,32);
tbl->GetColumns()->Append(_variant_t(col_ADDRESS,true),ADOX::adVarChar,66);
ADOX::_KeyPtr prkey(__uuidof(ADOX::Key));
prkey->PutName(_bstr_t(L"CustOrder"));
prkey->PutType(ADOX::adKeyPrimary);
ADOX::ColumnsPtr cols = prkey->GetColumns();
cols->Append(L"CID",ADOX::adInteger,0);
tbl->GetKeys()->Append(L"PK",ADOX::adKeyPrimary,_bstr_t(L"CID"),L"",L"");
cat->GetTables()->Append(_variant_t(tbl,true));
}
/* ***********************************************************************
*/
int wmain(int argc, char *argv[])
{
try
{
:

eleteFile("c:\\NewJet.mdb");
MakeDatabase();
}
catch(_com_error &e)
{
_bstr_t errm(e.ErrorMessage());
_bstr_t errd(e.Description());
printf("\nError...\n%S\n\n",(wchar_t *)errd);
}
return 0;
}