如何用TStringGrid+TQuery讀去SQL資料庫的資料! |
尚未結案
|
wireless80211g
一般會員 發表:9 回覆:7 積分:3 註冊:2005-10-22 發送簡訊給我 |
|
christie
資深會員 發表:30 回覆:299 積分:475 註冊:2005-03-25 發送簡訊給我 |
//舉例:以 TQuery 填 TStringGrid //For example: procedure TForm1.Button1Click(Sender: TObject); var i : INTEGER; begin i:=0; Query1.Close; Query1.DatabaseName:='DBDEMOS'; Query1.SQL.Clear; Query1.SQL.Add('SELECT * FROM VENDORS'); Query1.Open; // or Query1.Active:=True; StringGrid1.RowCount:=Query1.RecordCount 1; StringGrid1.FixedCols:=0; StringGrid1.Align:=alClient; // 表頭 WITH StringGrid1 DO BEGIN Cells[0,i]:=Query1.Fields[0].DisplayLabel; Cells[1,i]:=Query1.Fields[1].DisplayLabel; Cells[2,i]:=Query1.Fields[2].DisplayLabel; Cells[3,i]:=Query1.Fields[3].DisplayLabel; Cells[4,i]:=Query1.Fields[4].DisplayLabel; END; INC(i); // 資料填入Cells WHILE NOT Query1.Eof DO BEGIN WITH StringGrid1 DO BEGIN Cells[0,i]:=Query1.Fields[0].ASSTRING; Cells[1,i]:=Query1.Fields[1].ASSTRING; Cells[2,i]:=Query1.Fields[2].ASSTRING; Cells[3,i]:=Query1.Fields[3].ASSTRING; Cells[4,i]:=Query1.Fields[4].ASSTRING; END; Query1.Next; INC(i); END; end; Do it as best you can.
------
What do we live for if not to make life less difficult for each other? |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |