...eine Access Datenbank erzeugen?
|
Autor:
M.H. Avegaart |
[ Tip ausdrucken ] | | |
// 1: Using ADOX:
uses
ComObj;
// You can with ADOX (Microsoft ADO Extensions for DDL and Security),
function CreateAccessDatabase(FileName: string): string;
var
cat: OLEVariant;
begin
Result := '';
try
cat := CreateOleObject('ADOX.Catalog');
cat.Create('Provider=Microsoft.Jet.OLEDB.4.0;Data Source=' + FileName + ';');
cat := NULL;
except
on e: Exception do Result := e.message;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
CreateAccessDatabase('c:\Testdb.mdb');
end;
// 2: Using ODBC:
const
ODBC_ADD_DSN = 1; // Add data source
ODBC_CONFIG_DSN = 2; // Configure (edit) data source
ODBC_REMOVE_DSN = 3; // Remove data source
ODBC_ADD_SYS_DSN = 4; // add a system DSN
ODBC_CONFIG_SYS_DSN = 5; // Configure a system DSN
ODBC_REMOVE_SYS_DSN = 6; // remove a system DSN
ODBC_REMOVE_DEFAULT_DSN = 7; // remove the default DSN
function SQLConfigDataSource(hwndParent: HWND;
fRequest: Word;
lpszDriver: LPCSTR;
lpszAttributes: LPCSTR): BOOL; stdcall; external 'ODBCCP32.DLL';
function CreateDB(const Database: string): Boolean;
begin
Result := SQLConfigDataSource(0, ODBC_ADD_DSN,
'Microsoft Access Driver (*.mdb)', PChar('CREATE_DB=' + Database + ' General'#0));
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
CreateAccessDatabase('c:\Testdb.mdb');
end;
Bewerten Sie diesen Tipp:
|
|
|