When using ADO to connect the ACCESS database, I use the DBGRID display data, want to click on a row of DBGrid1, click the delete button to delete the selected after the line, using the code below:
Procedure TForm1. Btn4Click (Sender: TObject);
The begin
With qry1 do
The begin
The close;
Active:=True;
Edit;
The Delete.
The Update;
end;
end;
But in actual operation, no matter where I selected a line, it deleted data is always the first row of data
CodePudding user response:
According to your code, what kind of database connection is to delete the first lineDon't CLOSE, it is ok to directly DELETE
If Notqry. Eof then
Qry. DELETE;
This is ok
CodePudding user response:
You use the close, the current row data into the first line, then Delete to Delete the current line, just Delete the first line,Recommended code:
Procedure TForm1. Btn4Click (Sender: TObject);
The begin
With qry1 do
The begin
The Delete.
end;
end;
CodePudding user response:
If not qry1. IsEmpty thenQry1. Delete;
CodePudding user response:
When you are Close to the Active cursor automatically locate in the first articleCodePudding user response:
The three lines is superfluous, close is the root cause of the wrong delete data:The close;
Active:=True;
Edit;
CodePudding user response:
The close;Active:=True;
Said shut down first, and then open, so has always been the first, you can open the monitor to track the SQL statement,
CodePudding user response: