Forum Discussion

katenok29's avatar
New Contributor
14 years ago

How to insert Date type value into DB Table?

I use such string in delphi script to insert date-type value into table:

Cmd.CommandText := 'insert into MY_TABLE values(' '1' ', To_date(' '05.03.2010' ', ' '' '))'; 

Cmd.CommandType := DB.adCmdText;

When I call the method RecSet := Cmd.Execute all is ok. But now I want to insert value using parameter. I wrote:

Cmd.CommandText := 'insert into MY_TABLE values(' '1' ', ?)'; 

Cmd.CommandType := DB.adCmdText;

Prm:= Cmd.CreateParameter('date', DB.adDate, adParamInput);

Prm.Value := StrToDate('05.03.2010');



Now, when I call the method "RecSet := Cmd.Execute; " script can not stop and when I interupt it the message "stopping..."  appeares but script can't finish.

To stop the script execution the TestComplete process must be shuted down.

So, how can I insert into table value in date type field?

1 Reply

  • Hi Kate,

    The following sample script works fine for me when adding a record to a table in an SQL Server 2008 database:

    procedure TestProc;


      AConnection, RecSet, Cmd, Prm : OleVariant;


      AConnection := ADO.CreateConnection;

      AConnection.ConnectionString := 'Provider=SQLNCLI10;Server=myserver;Database=TestBase;Trusted_Connection=yes;';


      Cmd := ADO.CreateCommand;

      Cmd.ActiveConnection := AConnection;

      Cmd.CommandText := 'insert into [Persons] ([FirstName],[LastName],[BirthDate]) values (''John'', ''Doe'', ?)';

      Cmd.CommandType := adCmdText;

      Prm := Cmd.CreateParameter('MyParam', adDate, adParamInput);


      Prm.Value := StrToDate('05/20/1955');

      RecSet := Cmd.Execute;




    Please check whether you can modify this script for your case.