Re: fastest way to insert one record into a table

From: Arthur Hoornweg (arthur.hoornweg_at_wanadoo.nl.net)
Date: 07/12/04


Date: Mon, 12 Jul 2004 12:26:40 +0200


> Thanks. I'll try the TAdoCommand or even a native ADO command object
> approach and see where this will get me.
>

The tAdoconnection itself is quite enough. Here's a small
example on how to fill in string fields and how to
pass "null".

Note that the begintrans/committrans is by default not
mandatory on the OleDB provider for MSSQL - it treats
each SQL command as a transaction by default.
Still it's a good habit to work transaction-oriented.

VAR s,t:String;
begin
  s:='insert into mytable (name, street, city, age) values '+
   '%s, %s, %s, %s';

  t:=format(s,[ '''John Smith''' ,'''Fifth Avenue''',
     '''New York''', 'NULL']);

  adoconnection1.begintrans;
  try
    adoconnection1.execute(t);
    adoconnection1.committrans;
  except
   adoconnection1.rollbacktrans;
end;
end;

-- 
Arthur Hoornweg
(please remove the ".net" from my e-mail address)