OK



The following codes works fine:

procedure TMainForm.ws_deleteClick(Sender: TObject);
var
str:string;
begin
try
if application.MessageBox('confirm to delete?','Alert',MB_YESNO)=ID_YES
then
begin
str:=
tf_employee(activemdichild).dx1.DataSource.DataSet.Fields[1].AsString;

with dm.emp_sql do
begin
close;
sql.Clear;
sql.Add('delete from employees');
sql.Add('where job_id=:p');
parameters.ParamByName('p').Value :=str;
execsql;
end;

But still THANK YOU VERY MUCH.




"Bill Todd" <no@xxxxxx> дÈëÏûÏ¢ÐÂÎÅ:444d8483$1@xxxxxxxxxxxxxxxxxxxxxxxxx
DarkAngel wrote:


Hi, experts:

I use the following codes to delete a records from dbgrid:

adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('delete from employees where job_id=:p');
adoquery1.Parameters.ParamByName('p').Value
:=dbgrid1.DataSource.DataSet.Fields[1].AsString;

I suspect you want the value from the first field in the dataset which
would be dbgrid1.DataSource.DataSet.Fields[0].AsString.

adoquery1.ExecSQL;
adoquery1.Open;

You should not call both the ExecSQL and the Open methods. Never call
Open for any SQL statement except SELECT. Use ExecSQL for all SQL
statements that do not return a result set.


and I got an error saying 'List index out of bounds'.

Probably because you used Fields[1] instead of Fields[0].


--
Bill Todd (TeamB)


.



Relevant Pages

  • Re: list index out of bounds
    ... I use the following codes to delete a records from dbgrid: ... You should not call both the ExecSQL and the Open methods. ... Open for any SQL statement except SELECT. ...
    (borland.public.delphi.database.ado)
  • Re: list index out of bounds
    ... I suspect you want the value from the first field in the dataset which ... You should not call both the ExecSQL and the Open methods. ... Open for any SQL statement except SELECT. ...
    (borland.public.delphi.database.ado)
  • Re: NLS_DATE_FORMAT in jdbc
    ... Please see my codes below. ... ALTER SESSION SQL statement. ... date format I want in the "alter session" statement. ...
    (comp.databases.oracle.misc)
  • Re: Splitting databases
    ... Set rs = db.OpenRecordset (strSQL) ... Or perhaps even simpler is just execute an SQL statement ... if the user decides to cancel the operation the code returns ... to the Codes table and subtracts 1 from the existing number. ...
    (microsoft.public.access.gettingstarted)
  • Re: NLS_DATE_FORMAT in jdbc
    ... to set NLS_DATE_FORMAT inside jdbc, it didn't seem to have any effect. ... Please see my codes below. ... ResultSet rs=stat.executeQuery("select trade_date from ... ALTER SESSION SQL statement. ...
    (comp.databases.oracle.misc)