Page 1 of 1
Feature TMyCommand
Posted: Wed 24 Sep 2008 13:38
by jkuiper
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.
Posted: Mon 29 Sep 2008 08:52
by Dimon
On arising of error TMyCommand should raise the same error that TMyQuery.
Please try to compose a small sample to demonstrate the problem and send it to dmitryg*devart*com.
Re: Feature TMyCommand
Posted: Wed 27 Feb 2013 09:28
by john_kuiper
Sorry for the very late reply
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;
It is not telling why the delete does not work. TMyCommand does not have de event OnPostError.
Re: Feature TMyCommand
Posted: Wed 27 Feb 2013 17:48
by DemetrionQ
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:
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;
use the OnError event of the TMyConnection component, for example:
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;