treeview的使用,把query改成adoquery |
缺席
|
luowy651
高階會員 發表:257 回覆:313 積分:114 註冊:2003-04-09 發送簡訊給我 |
请教各位大大,下面这段code是用于query,可以用,但我想改成adoquery,却怎么也改不成,能否请大大帮忙碌,小弟先谢过了! ps: 我已把pardox的那个资料库转为mssql中的table了,table的名字一样,是: leechdom 完整的檔案code : delphi.ktop.com.tw/download.php unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ComCtrls, DB, DBTables, ExtCtrls, jpeg; type TForm1 = class(TForm) TreeView1: TTreeView; Query1: TQuery; Panel1: TPanel; Image1: TImage; procedure FormCreate(Sender: TObject); private { Private declarations } public Procedure FindLeechDom(Leechdomname: String;node: TTreeNode); { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.FindLeechDom(Leechdomname: String;node: TTreeNode); var temp: TQuery; node1: TTreeNode; begin Try temp := TQuery.Create(Self); temp.DatabaseName := ExtractFilePath(Application.ExeName); With temp do begin Close; SQL.Clear; SQL.Add('select * from leechdom.db where 上级编码 = :Value'); ParamByName('value').AsString := Leechdomname; Open; end; while Not Temp.Eof do begin node1 := TreeView1.Items.AddChild(node,temp.FieldByName('药品类别').AsString); FindLeechDom(temp.FieldByName('药品类别').AsString,node1); temp.Next; end; Finally temp.Free; end; end; procedure TForm1.FormCreate(Sender: TObject); var temp: TTreeNode; begin if FileExists(ExtractFilePath(Application.ExeName) 'leechdom.db') then begin Query1.DatabaseName := ExtractFilePath(Application.ExeName); With Query1 do begin Close; SQL.Clear; SQL.Add('select * from leechdom.db'); Open; end; while not Query1.Eof do begin if Query1.FieldByName('上级编码').AsString = '' then begin temp := TreeView1.Items.AddChild(TreeView1.Items[0],Query1.FieldByName('药品类别').AsString); FindLeechDom(Query1.FieldByName('药品类别').AsString,temp); end; Query1.Next; end; end; end; end. |
AndrewK
高階會員 發表:6 回覆:151 積分:161 註冊:2006-10-09 發送簡訊給我 |
|
luowy651
高階會員 發表:257 回覆:313 積分:114 註冊:2003-04-09 發送簡訊給我 |
|
luowy651
高階會員 發表:257 回覆:313 積分:114 註冊:2003-04-09 發送簡訊給我 |
非常感谢小傑克大大的侠义相助,问题得到圆满解决,小傑克大大修改后的程式下载链接如下:
http://www.4shared.com/file/91419056/a72fe7b6/test1.html 我把其中的code帖一下: unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, DB, ADODB, ComCtrls, StdCtrls; type TForm1 = class(TForm) Button1: TButton; TreeView1: TTreeView; ADOConnection1: TADOConnection; ADOQuery1: TADOQuery; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } function ConnectIonDataBase:Boolean; function GetAdoQuery(sSql:String):TADOQuery; Procedure FindLeechDom(Leechdomname: String;node: TTreeNode); end; var Form1: TForm1; implementation {$R *.dfm} function TForm1.ConnectIonDataBase: Boolean; begin // try connect adoConn to database Result := false; ADOConnection1.Close; ADOConnection1.ConnectionString := 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=' ExtractFilePath( Application.ExeName) '\test1.mdb;Persist Security Info=False'; try ADOConnection1.Open; Result := true; except end; end; procedure TForm1.Button1Click(Sender: TObject); var q:TADOQuery; o,temp: TTreeNode; begin if ConnectIonDataBase then begin TreeView1.Items.Add(nil,'MTYPE'); q := GetAdoQuery('SELECT * FROM LEECHDOM WHERE MCODE IS NULL '); while not q.Eof do begin temp := TreeView1.Items.AddChild( TreeView1.Items[0],q.FieldByName('MTYPE').AsString); FindLeechDom(q.FieldByName('MTYPE').AsString ,temp); q.Next; end; q.Close; q.Free; end; end; function TForm1.GetAdoQuery(sSql: String): TADOQuery; var q:TADOQuery; begin try q := TADOQuery.Create(nil); q.Connection := ADOConnection1; q.Close; q.SQL.Text := sSql; q.Open; Result := q; except on E:Exception do Raise e; end; end; procedure TForm1.FindLeechDom(Leechdomname: String; node: TTreeNode); var temp: TADOQuery; node1: TTreeNode; begin Try temp :=GetAdoQuery('SELECT * FROM LEECHDOM WHERE MCODE=' QuotedStr(Leechdomname)); while Not Temp.Eof do begin node1 := TreeView1.Items.AddChild(node,temp.FieldByName('MTYPE').AsString); FindLeechDom(temp.FieldByName('MTYPE').AsString,node1); temp.Next; end; Finally temp.Close; temp.Free; end; end; end. |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |