Console app to write to MS Access database



Hi all,

I am fairly new to Delphi so could someone look at this code for me and

tell me if it is any good. It works but I am not sure if it is the
right way to do it. It is a simple console app that writes to an Access

database.


I had to add "ActiveX" of all things to "Uses" to get
CoInitialize/CoUninitialize to work is that the right one?


Thanks in advance!

M.

Code follows...

uses
ADODB, ActiveX;


Var
ADOTable1: TADOTable;
begin

{ TODO -oUser -cConsole Main : Insert code here }

Writeln('Opening database...');

CoInitialize(nil);
try
ADOTable1 := TADOTable.Create(nil);
try
ADOTable1.ConnectionString :=
'Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=D:\ctgwork\Databases\FTPrecords.mdb;Persist Security Info=False'
;
ADOTable1.Name := 'ADOTable1';
ADOTable1.TableName := 'Table1';
try
ADOTable1.Open;
ADOTable1.Append;
ADOTable1.FieldByName('ZipFileName').AsString := 'Hello World
11:45';
ADOTable1.Post;
finally
ADOTable1.Close;
end;
finally
ADOTable1.Free;
end; // try
finally
CoUninitialize();
end; //try

Writeln('Done!');
end.

.



Relevant Pages

  • Console app to write to MS Access database
    ... I am fairly new to Delphi so could someone look at this code for me and tell ... database. ... ADOTable1:= TADOTable.Create; ... Persist Security Info=False'; ...
    (borland.public.delphi.database.ado)
  • Re: Delphi Jobs
    ... I am a Delphi database programmer. ... Source Safe and Source Off Site on the server side and client side. ... design several pieces for the interactive website. ...
    (comp.lang.pascal.delphi.misc)
  • Re: Embarcaderos Director of Products Blog
    ... What indications were there that it was difficult to sell, ... but Delphi has ALWAYS been about database development. ... All of which DO make perfect sense and could be seen as having a home at ...
    (borland.public.delphi.non-technical)
  • Software specifications
    ... I have been frustrated in this project because my software and hardware is ... another programmer who has been my mentor in Delphi, ... me when it will be ready, as they are struggling with old MSDOS software ... could do the entire database project myself, ...
    (comp.lang.pascal.delphi.misc)
  • Database Landscape for future Delphi work.
    ... I'm a died-in-the-wool Delphi fan, and have been programming in Delphi since ... So I switched my database to Jet 4.0 and to using ADO via Delphi's ... Good support for syncing w/ SQL Server. ...
    (borland.public.delphi.non-technical)