Einzelnen Beitrag anzeigen

Benutzerbild von x000x
x000x

Registriert seit: 21. Jan 2004
Ort: Bei Hamburg
308 Beiträge
 
Delphi XE2 Professional
 
#5

Re: Access 2.0 DB erstellen oder von Access 2003 in 2.0 kon

  Alt 29. Okt 2005, 21:14
Moin moin,

probier mal folgende function:
Delphi-Quellcode:
uses {..,}Variants, ComObj{,..};
//..
Const
   Jet10 = 1;
   Jet11 = 2;
   Jet20 = 3;
   Jet3x = 4;
   Jet4x = 5;

function CreateAccessDatabase(const FileName: String; const Version: Integer; DelIfExists: Boolean = False): string;
var
   cat: OLEVariant;
begin
   Result := '';
   if FileExists(FileName) And DelIfExists then
      DeleteFile(FileName);
   try
      cat := CreateOleObject('ADOX.Catalog');
      cat.Create('Provider=Microsoft.Jet.OLEDB.4.0;'+
                 'Jet OLEDB:Engine Type='+IntToStr(Version)+';'+
                 'Data Source=' + FileName + ';');
      cat := NULL;
  except
      on e: Exception do Result := e.message;
  end;
end;

procedure TForm1.Button1.Click(Sender: TObject);
begin
   CreateAccessDatabase('test.mdb', Jet20);
end;
//..
bzw. ähnlich deinem obigem VB:
Delphi-Quellcode:
uses {..,}Variants, ComObj{,..};
//..
const
   dbVersion10 = 1;
   dbVersion11 = 8;
   dbVersion20 = 16;
   dbVersion30 = 32;
   dbVersion40 = 64;

function CreateDB(const FileName: String; const Version: Integer; DelIfExists: Boolean = False): String;
var
   DBEngine,
   Workspace,
   Database : OleVariant;
   s : String;
const
   dbLangGeneral = ';LANGID=0x0409;';
begin
   Result := '';
   if FileExists(FileName) And DelIfExists then
      DeleteFile(FileName);
   s := dbLangGeneral + 'CP=' + IntToStr(GetACP()) + ';COUNTRY=0';
   DBEngine:= CreateOleObject('DAO.DBEngine.36');
   try
      try
         Workspace := DBEngine.Workspaces[0];
         Database := Workspace.CreateDatabase(FileName, s, Version);
         Database.Close;
         Workspace.Close;
      except
         On E: Exception do
            Result := E.Message;
      end;
   finally
      Database := NULL;
      Workspace := NULL;
      DBEngine := NULL;
   end;
end;

procedure TForm1.Button1.Click(Sender: TObject);
begin
   CreateDB('test.mdb', dbVersion20);
end;
Peter
-= Gruss Peter =-
-= alias x000x =-
  Mit Zitat antworten Zitat