Link to home
Create AccountLog in
Avatar of bjones8888
bjones8888Flag for United States of America

asked on

Executing simple 'Delete' statement using ADO Command object

I'm using Delphi 2006 Architect, but what I'm trying to do has been around for years - I'm just not familiar with how to get it done (and I've been frustrated all day trying to get this done).

I have a service application which is reading through a set of records from a SQL Server table.  That works great.  

At the end of the program logic, I want to delete all the records I just stepped through.  I'm marking them with a value as I go.

Here's my code:

  lRecsAffected := 0;
  ADOCommand := CoCommand.Create;
  ADOCommand._Set_ActiveConnection(FConnectionString);
  ADOCommand.CommandText := 'Delete from CalendarLog where Operation = ''DELETE''';
  ADOCommand.CommandType := adCmdText or adExecuteNoRecords;
  ADOParameter := ADOCommand.CreateParameter('ADOParameter', adEmpty, adParamInput, 0, 0);
  ADOCommand.Execute(lRecsAffected, ADOParameter, adCmdText or adExecuteNoRecords);

lRecsAffected is defined as OleVariant, and so is ADOParameter.  ADOCommand is _Command.

I would rather not have anything to do with the Parameter object, but I'm assuming it's a necessary evil at this point.  All I want to do is execute my delete statement.  Help!
Avatar of bjones8888
bjones8888
Flag of United States of America image

ASKER

... more info:

FConnectionString is just that - the database connection string.

The error I'm getting is "EOleException - Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another"

I've tried just about every combination I can think of, but I'm just shooting in the dark.
SOLUTION
Avatar of saravananvg
saravananvg
Flag of India image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Use a TADOQuery rather than a TADOCommand. What you're doing is executing a query, after all.

I'm told that it's best not to use VCL components in a service application because of memory leaks.  I need to use the ADOCommand object from ADOInt.pas.
SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER CERTIFIED SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Thank you all for your comments.  They were all helpful.