Re: Console app to write to MS Access database
- From: "Viatcheslav V. Vassiliev" <support@xxxxxxxxxxxxxxx>
- Date: Mon, 20 Feb 2006 11:31:40 +0300
CoInitialize() is called in InitProc from ComObj unit. Console applications
do not call this procedure, but you may do it (first line in your
application):
if InitProc <> nil then TProcedure(InitProc);
//------------------------------------------
Regards,
Vassiliev V. V.
http://www.managed-vcl.com - using .Net objects in Delphi for Win32 +
ADO.Net
http://www.oledbdirect.com - The fastest way to access MS SQL Server,
MS Jet (Access) and Interbase (through OLEDB)
"mac32bit" <mac32bit@xxxxxxxxxxx> ÓÏÏÂÝÉÌ/ÓÏÏÂÝÉÌÁ × ÎÏ×ÏÓÔÑÈ ÓÌÅÄÕÀÝÅÅ:
news:43f8be05$1@xxxxxxxxxxxxxxxxxxxxxxxxx
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.
.
- References:
- Console app to write to MS Access database
- From: mac32bit
- Console app to write to MS Access database
- Prev by Date: Re: Master-Detail with ADODataSet
- Next by Date: An unknown error has occured...
- Previous by thread: Re: Console app to write to MS Access database
- Next by thread: An unknown error has occured...
- Index(es):