How to search specific and locate the record? |
尚未結案
|
Vashee
初階會員 發表:38 回覆:87 積分:25 註冊:2003-03-31 發送簡訊給我 |
I have been looking for tutorials in Delphi.About.com
i have found some method of locating records, but the coding make no sense to me: AdoTable1.Locate('Name','Zoom',[]); {...or...} var ffield, fvalue: string;
opts : TLocateOptions;
ffield := 'Name';
fvalue := 'zoom';
opts := [loCaseInsensitive]; if not AdoTable1.Locate(ffield, fvalue, opts) then
ShowMessage(fvalue ' not found in ' ffield); I don't really understand what it means
what I really trying to find out is when I type in a specific ID into edit and it search throught the database and select the targeting record. Can anyone help me
thanx for advance
|
hahalin
版主 發表:295 回覆:1698 積分:823 註冊:2002-04-14 發送簡訊給我 |
還有一種做法 參考看看 1.要讓使用者能夠依據輸入的條件來查詢資料 可以動態建立一個adoquery,sql 語法可以是 select field1 from table1 where field1 like '條件%' 2.當確定搜尋出來,並指定record後,你可以 依照這個record的值再去原來的dataset進行locate或是filter的動 做。Fear is the path to the dark side. Fear leads to anger.Anger leads to hate.Hate leads to suffering.... |
timhuang
尊榮會員 發表:78 回覆:1815 積分:1608 註冊:2002-07-15 發送簡訊給我 |
引言: I don't really understand what it means what I really trying to find out is when I type in a specific ID into edit and it search throught the database and select the targeting record.Locate function is used to locate a record in dataset, not send command to server to get the matched data. If you want to seach throught the database, you should use sql command to get the data. Like hahalin said, use the sql command like SELECT * FROM TABLE1 WHERE NAME LIKE 'zoom%' -- for zoom1 zoomxya ... etc. SELECT * FROM TABLE1 WHERE NAME = 'zoom' -- for exactly equal zoom |
Vashee
初階會員 發表:38 回覆:87 積分:25 註冊:2003-03-31 發送簡訊給我 |
My situation is a alittle different. basically, there are two separate searching occur at the at same.
first I use the dataset.sql.command to search throught (Table1), if the record is found in (Table1), when I press enter, the selected record will be copied to (Table2). Now, here the situation gets complicated. when I try to search throught (Table1) again, but if the same record exist in (Table2) already, when I press enter that record in (Table 2) will be selected. Do u see what I mean? this is to make sure there is no duplicated record inserted into (table2)
|
Vashee
初階會員 發表:38 回覆:87 積分:25 註冊:2003-03-31 發送簡訊給我 |
I will try to make this more clear: so when I key in a specific record ID into Tedit.
it perform a double searching throught 2 tables. if record is not found is table2 then searh throught table 1
if record is found in table2, then DO NOT search throught table 1
and instead select that record in table2
|
hahalin
版主 發表:295 回覆:1698 積分:823 註冊:2002-04-14 發送簡訊給我 |
引言: if record is not found is table2 then searh throught table 1 if record is found in table2, then DO NOT search throught table 1 and instead select that record in table2 try this.. STEP1: Select the record in table1 by using the edit's text value as the key. STEP2: If the record is found in table1 then begin Do the next setp with the record is found in table1 end else begin Select the record in table2 by using the edit's text value as the key if the record is found in table2 then begin Do the next setp with the record is found in table2 end else begin Do the next setp with no record is found in table1 and table2 end end;Is the answer clear enough to satisfy your need? -_- Fear is the path to the dark side. Fear leads to anger.Anger leads to hate.Hate leads to suffering.... 發表人 - hahalin 於 2003/04/13 23:02:23 |
Vashee
初階會員 發表:38 回覆:87 積分:25 註冊:2003-03-31 發送簡訊給我 |
|
hahalin
版主 發表:295 回覆:1698 積分:823 註冊:2002-04-14 發送簡訊給我 |
引言: but i need how is the code written. ex: The form has a adoquery and its name is 'dt1'. The form has a edit and its name is 'ed1'. function tosearch:boolean; begin dt1.close; dt1.sql.text:='select field1 from table1 where field1 like ' +quotedstr(ed1.text+'%'); //in MS ACCESS , replace the '%' by '*' dt1.open; //Check the record,the recordset's bof and eof will be //in the same position when recordset is empty. if the dt1.bof=dt1.eof then result:=false else result:=true; end; You can read the post by click the link below to get some idea to design the system. http://delphi.ktop.com.tw/topic.php?TOPIC_ID=25603 Good luck!!!Fear is the path to the dark side. Fear leads to anger.Anger leads to hate.Hate leads to suffering.... 發表人 - hahalin 於 2003/04/14 07:37:25 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |