(Gast)
n/a Beiträge
|
Re: Mit TurboDelphi Datenbank anlegen
5. Nov 2009, 19:47
Habe folgenden Code mal irgendwoher in meine Codesammlung kopiert. Weiss die Quelle nicht mehr.
Delphi-Quellcode:
uses
SysUtils, ActiveX, Variants, ADOX_TLB in ' ADOX_TLB.pas', ADODB_TLB in ' ADODB_TLB.pas';
procedure NewDatabase;
var
Catalog: _Catalog;
Connection: _Connection;
Command: _Command;
Parameters: OleVariant;
RecordsAffected: OleVariant;
begin
Catalog := CoCatalog.Create;
try
Catalog.Create(' Provider=Microsoft.Jet.OLEDB.4.0;Data Source="D:\Test.mdb";Jet OLEDB:Engine Type=5;Jet OLEDB:Database Password=hello;');
if Succeeded(IUnknown(Catalog.Get_ActiveConnection).QueryInterface(_Connection, Connection)) and Assigned(Connection) then
begin
Command := CoCommand.Create;
try
Command.CommandTimeout := 0;
Command.Set_ActiveConnection(Connection);
Command.CommandText := ' create table ApplePie(ID SmallInt, Name Text(20));';
Parameters := EmptyParam;
Command.Execute(RecordsAffected, Parameters, 0);
except
end;
end;
finally Catalog := nil;
end;
end;
begin
CoInitialize( nil);
try
NewDatabase;
except on E: Exception do WriteLn(StringOfChar(' =', 80), #13#10, E. Message);
end;
CoUninitialize;
end.
|
|
Zitat
|