1

I want to delete rows from a grid when I click on a button. How can I do that?

procedure TFormAna.ptal1Click(Sender: TObject);
begin
  QSilMaster.Close;
  QSilDetay.Close;
  QSilMaster.SQL.Text:='delete from IsTakipMaster where id=:pMasterid';
  QSilDetay.SQL.Text:='delete from IsTakipDetay where Masterid=:pid';
  QSilMaster.ExecSQL;
  QSilDetay.ExecSQL;
  QSilMaster.Open;
  QSilDetay.Open;
  //dm.QGenel.Parameters.ParamValues['pid']:=QSilMasterid.Value;
  //dm.QGenel.Parameters.ParamValues['pMasterid']:=QSilDetayMasterid.Value;
  QSilMasterid.Value:=QSilDetayMasterid.Value;
end;

I get this error message:

CommandText does not return a result set

Why do I get this error, and how can I fix it?

1
  • 4
    DELETE does not return a result set, because it does a DELETE. What result set would you expect? The DELETEd rows? They can't be returned - they've been deleted. DELETE, INSERT and UPDATE will tell you how many rows were changed with the RowsAffected property. SELECT returns a result set. You're getting the error on the calls to Open, which are only used for SELECT. Use ExecSQL for INSERT, UPDATE and DELETE. Commented Mar 5, 2021 at 13:52

1 Answer 1

1

It depends on the component you use for QSilMaster and QSilDetay. But usually you call either ExecSQL or Open but not both. Use ExecSQL for a request which doesn't return any result set (such as your DELETE) and Open for a request returning a result set (Such as a SELECT).

Sign up to request clarification or add additional context in comments.

1 Comment

@berk Cinaz Sorry to bother you more, but you still have not accepted my answer. It is the "tick mark" that you have to use.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.