Using the mouse to select a ListView1 line
Then the program will be selected in a row to delete
O program ~ ~ ~
Even at the same time also delete the data from the access ~
Procedure TForm10. Button2Click (Sender: TObject);//is not here, you want to delete the selected item at the same time the call also delete a database)
The begin
?????????????????????????
end;
Procedure TForm10. Button4Click (Sender: TObject);//(here is according to the courses' ' 'is this a filtering to delete the line, and delete the information in the access database)
The begin
????????????????????
end;
End.
O god ~ ~ ~
CodePudding user response:
VarI: integer;
The begin
For I:=ListView1. Downto Items. The Count - 1 0 do
If ListView1. Items [I]. Selected then
With DataModule9. ADOQuery1 do
The begin
SQL. The Clear;
SQL. The Add (' delete * from students' course selection where student id=: student id ');
The Parameters. ParamByName (' student id '). The Value:=ListView1. Items [I] Caption;
ExecSQL;
ListView1. Items. The Delete (I);
Application. The MessageBox (' information deleted successfully! ', 'prompt', mb_ok);
end;
end;
It is through the "course id" screening information and delete the program, but did not use the
O modify
CodePudding user response:
Used this function, etc. Will help you to look at my codeCodePudding user response:
VarI: integer;
The begin
For I:=ListView1. Downto Items. The Count - 1 0 do
If ListView1. Items [I]. Selected then
The begin
With DataModule9. ADOQuery1 do
The begin
SQL. The Clear;
SQL. Add (' delete from course where students (student id="' + ListView1. Items. The Item [I] Caption + '"));
ExecSQL;
ListView1. Items. The Item [I]. Delete;
Showmessage (' list data deleted successful! ');
end;
break;
end;
end;
CodePudding user response:
Why use ListView? With the DBGrid not more convenient?CodePudding user response:
Try this modification:
Procedure TForm1. Button2Click (Sender: TObject);
Var I: integer;
SSQL: string;
The begin
For I:=ListView1. Downto Items. The Count - 1 0 do
If ListView1. Items [I]. Selected then
The begin
With ADOQuery1 do
The begin
SSQL:='delete from course where students (student id=' + # 39 + ListView1. Items. The Item [I] Caption + # 39 + ') '.
SQL. The Clear;
SQL. The Add (sSQL);
ExecSQL;
ListView1. Items. The Item [I]. Delete;
//showmessage (' list data deleted successful! ');
end;
end;
end;
CodePudding user response:
According to the key to delete data in the databaseRefresh the listview