bjones8888
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_ActiveConn ection(FCo nnectionSt ring);
ADOCommand.CommandText := 'Delete from CalendarLog where Operation = ''DELETE''';
ADOCommand.CommandType := adCmdText or adExecuteNoRecords;
ADOParameter := ADOCommand.CreateParameter ('ADOParam eter', adEmpty, adParamInput, 0, 0);
ADOCommand.Execute(lRecsAf fected, 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!
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_ActiveConn
ADOCommand.CommandText := 'Delete from CalendarLog where Operation = ''DELETE''';
ADOCommand.CommandType := adCmdText or adExecuteNoRecords;
ADOParameter := ADOCommand.CreateParameter
ADOCommand.Execute(lRecsAf
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!
SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Use a TADOQuery rather than a TADOCommand. What you're doing is executing a query, after all.
ASKER
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
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Thank you all for your comments. They were all helpful.
ASKER
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.