Home > Back-end >  Using ADO to connect the ACCESS, delete data always delete the wrong data, online etc.!!!!!!
Using ADO to connect the ACCESS, delete data always delete the wrong data, online etc.!!!!!!

Time:09-17

Each great spirit:

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 line

Don'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 then
Qry1. Delete;

CodePudding user response:

When you are Close to the Active cursor automatically locate in the first article

CodePudding 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:

refer to the second floor lyhoo163 response:
close you use, 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;
it is ok,,,,

CodePudding user response:

Delete a row, it is necessary to add the where condition decision, this will delete is wrong, as with qry1 do delete; It is wrong to

CodePudding user response:

Select a line, direct delete, where still need to close, active

CodePudding user response:

Year, the building Lord junction post,

CodePudding user response:

Basic it is asked the ran, wow ha ha ha

CodePudding user response:

With qry1 do
The begin
The close; The closed qry1
Active:=True;
Edit;
The Delete. Here to delete, not you selected that records the data set is opened, the default is the first article,
The Update;
end;
  • Related