Is it possible to make a feature on TMyCommand to give a good errormessage. Now you can check only on rowsaffected. If it is -1, it tells the insert / update /delete has failed. It's easier go get the right databaseerror to see what's rely going on. An onError event should also be nice.
I know I can use TMyQuery. But as far as I know Devart alswas tell to use TMyCommand, because it's mutch faster.
Feature TMyCommand
-
john_kuiper
- Posts: 19
- Joined: Tue 15 May 2012 09:34
Re: Feature TMyCommand
Sorry for the very late reply
It is not telling why the delete does not work. TMyCommand does not have de event OnPostError.
Code: Select all
procedure TDMFactwizard.ClearFust(const snr : integer);
var MyCMD : TMyCommand;
begin
MyCMD := TMyCommand.Create(nil);
try
MyCMD.Connection := dmalg.MyConnection1;
MyCMD.SQL.Text := 'DELETE FROM fustadminverkoop WHERE verkooporderID = :snr';
MyCMD.Params[0].Value := snr;
MyCMD.Execute;
if MyCMD.RowsAffected = -1 then
showmessage('error deleting fustadminverkoop');
finally
MyCMD.Free;
end;
end;
-
DemetrionQ
- Devart Team
- Posts: 271
- Joined: Wed 23 Jan 2013 11:21
Re: Feature TMyCommand
Hello.
If no record is deleted, then MyCMD.RowsAffected = 0. This is not an error: there just was no such records in the table when query was executed. If, on execution of the query (the MyCMD.Execute), an SQL Error occurs (for example, you have specified a nonexistent table or field), and you need to retrieve the information about this error, you can use one of the following ways:
use the "on e: Exception do" instruction, for example:
use the OnError event of the TMyConnection component, for example:
If no record is deleted, then MyCMD.RowsAffected = 0. This is not an error: there just was no such records in the table when query was executed. If, on execution of the query (the MyCMD.Execute), an SQL Error occurs (for example, you have specified a nonexistent table or field), and you need to retrieve the information about this error, you can use one of the following ways:
use the "on e: Exception do" instruction, for example:
Code: Select all
try
MyCMD.SQL.Text := 'DELETE FROM fustadminverkoop WHERE verkooporderID = :snr';
MyCMD.Params[0].Value := snr;
MyCMD.Execute;
except
on e: Exception do begin
ShowMessage('Error :' + e.Message);
end;
end;Code: Select all
procedure TForm1.MyConnection1Error(Sender: TObject; E: EDAError;
var Fail: Boolean);
begin
ShowMessage('Error :' + E.Message);
Fail := False; //in order for the system error message not to appear
end;