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 is a simple console app that writes to an
Access database.

It works but I am not sure if it is the right way to do it.

I had to add "ActiveX" 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:\Databases\Frecords.mdb;
Persist Security Info=False';

ADOTable1.Name := 'ADOTable1';
ADOTable1.TableName := 'Table1';
try
ADOTable1.Open;
ADOTable1.Append;
ADOTable1.FieldByName('ZipFileName').AsString := 'Hello World';

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 ... ADOTable1:= TADOTable.Create; ... Persist Security Info=False'; ... CoUninitialize(); ...
    (borland.public.delphi.database.ado)
  • 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: A thread using a COM object crashes...
    ... You have to call CoInitialize (and CoUninitialize) ... Delphi does it automatically for the main thread. ... Chris ...
    (borland.public.delphi.language.objectpascal)
  • Console app to write to MS Access database
    ... I am fairly new to Delphi so could someone look at this code for me and ... database. ... CoInitialize/CoUninitialize to work is that the right one? ... ADOTable1:= TADOTable.Create; ...
    (borland.public.delphi.database.ado)