I want to add items from a query into a TListView using a for loop. But I get an error saying 'Too many actual parameters' from the ListViewShifts.Items.Add() line. What is the correct way of adding to the list from a query?
Qry := TFDQuery.Create(DBConnection);
Qry.Connection := DBConnection;
Qry.SQL.Text := 'SELECT Count(10) FROM Bookings WHERE NurseNo=:nurseID;';
Qry.Params.ParamByName('nurseID').AsInteger := NurseID;
Qry.Active := True;
//Fill the list view with the shifts that have the nurses ID
for Count := 0 to 10 do
begin
ListViewShifts.Items.Add(Qry.Fields[Count].AsString);
end;
You need to consider the following:
ListViewShiftsvariable isTListView, methodListViewShifts.Items.Adddoesn't expect parameters. This is the reason forToo many actual parameterserror.SELECT Count(10) FROM Bookings WHERE NurseNo=:nurseID;will return result set with only one column.SELECT TOP(10) FROM Bookings WHERE NurseNo=:nurseID;First,EofandNextdataset methods to fetch records from your result set.Next basic example shows how to add 10 items in your
TListView: