whats new ¦  programming tips ¦  indy articles ¦  intraweb articles ¦  informations ¦  links ¦  interviews
 misc ¦  tutorials ¦  Add&Win Game

Tips (1541)

Database (90)
Files (137)
Forms (107)
Graphic (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Math (76)
Misc (126)
Multimedia (45)
Objects/
ActiveX (51)

OpenTools API (3)
Printing (35)
Strings (83)
System (266)
VCL (242)

Top15

Tips sort by
component


Search Tip

Add new Tip

Add&Win Game

Advertising

52 Visitors Online


 
...create an Access Database?
Autor: M.H. Avegaart
[ Print tip ]  

Tip Rating (49):  
     


// 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; stdcallexternal '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;

 

Rate this tip:

poor
very good


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners