with dmHospital do
begin
qryHospital.SQL.Clear;
qryHospital.SQL.Add('SELECT * FROM Patients ') ;
qryHospital.SQL.Add('WHERE DoctorID = :DoctorID');
qryHospital.Parameters.ParamByName('DoctorID').Value := StrToInt(sID);
qryHospital.Open;
iCount := qryHospital.RecordCount
end;
이 코드는 배열에 넣을 값을 표시합니다. 그러나 각 레코드를 순환하고 레코드의 각 값을 올바른 배열로 가져 오는 방법을 잘 모르겠습니다. 예 : 'PatientName'의 이름과 'PatientSurname'의 성을 원합니다. iCount는 배열 크기입니다.
를 TDataset
사용하여 반복해야합니다 While
.
일부 샘플 코드 :
...
var
fieldCod:TField;
Str1:String;
i, Cod:Integer;
begin
...
qryHospital.Open;
iCount := qryHospital.RecordCount;
// Create pointer to field
fieldCod := qryHospital.FieldByName('PatientCode');
// loop the recordset (while not arrive at end)
While (not qryHospital.eof) do begin
// Different modes to access table fields content
Str1 := qryHospital.FieldByName('PatientName').AsString;
i := qryHospital.Fields[1].AsInteger;
Cod := fieldCod.AsInteger;
// Add the values to your array
//...
// Next Record
qryHospital.Next;
end;
참고 : 더 나은 성능을 FieldByName
위해 루프 내부에서 사용하지 마십시오 (많은 레코드의 경우). Fields[index]
루프 및 필드 참조에서 변수를 사용 하거나 만들 수 있습니다 .
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다