轉換郵遞區號並傳查詢值 |
尚未結案
|
jawtair
一般會員 發表:30 回覆:92 積分:24 註冊:2003-04-26 發送簡訊給我 |
這是我使用的元件結構
SQL資料庫<--ADOConnection1<--ADOQuery1<--DataSource1 請問各位先見,我使用資料庫為ccpm,假設裡面有兩個資料庫
pm3d 會員基本資料,裡面有欄位
A11 郵遞區號 300
A12 縣市 新竹市
A13 地址 東大路二段200號 PM5D 郵遞區號對照碼資料庫,裡面有欄位
PM5D1 郵遞區號 300
PM5D2 縣市 新竹市 請問是否可以在使用者,在A11欄位輸入300時,系統自動查詢,並且把值「新竹市」傳給A12 反之當使用者,在A12輸入「新竹市」時,系統自動查詢,共且把值300傳給A11 有可能這樣做嗎?盼那位先見能指導,謝謝大家。
|
Justmade
版主 發表:94 回覆:1934 積分:2030 註冊:2003-03-12 發送簡訊給我 |
dbEditA11 的 onChange : if QueryPM5D.Locate('PM5D1',QueryPM3D.FieldByName('A11').Value,[]) and QueryPM3D.FieldByName('A12').Value <> QueryPM5D.FieldByName('PM5D2').Value then QueryPM3D.FieldByName('A12').Value := QueryPM5D.FieldByName('PM5D2').Value; dbEditA12 的 onChange : if QueryPM5D.Locate('PM5D2',QueryPM3D.FieldByName('A12').Value,[]) and QueryPM3D.FieldByName('A11').Value <> QueryPM5D.FieldByName('PM5D1').Value then QueryPM3D.FieldByName('A11').Value := QueryPM5D.FieldByName('PM5D1').Value; |
jawtair
一般會員 發表:30 回覆:92 積分:24 註冊:2003-04-26 發送簡訊給我 |
引言:Justmade版主您好: 感謝您在百忙之中,抽空回答,關於您所提的解答,乍看來已了解寫法,但心中仍有些疑問如下:dbEditA11 的 onChange : if QueryPM5D.Locate('PM5D1',QueryPM3D.FieldByName('A11').Value,[]) and QueryPM3D.FieldByName('A12').Value <> QueryPM5D.FieldByName('PM5D2').Value then QueryPM3D.FieldByName('A12').Value := QueryPM5D.FieldByName('PM5D2').Value;
|
jawtair
一般會員 發表:30 回覆:92 積分:24 註冊:2003-04-26 發送簡訊給我 |
試了好久, 仍然不行, 會出現錯誤訊息:
[Hint] Unit2.pas(85): Variable 'Emp_No' is declared but never used in 'TForm2.SpeedButton8Click'
[Warning] Unit2.pas(132): Unsafe type 'PChar'
[Warning] Unit2.pas(135): Unsafe code 'GetMem'
[Warning] Unit2.pas(135): Unsafe type 'PCha1: PAnsiChar'
[Warning] Unit2.pas(137): Unsafe type 'PCha1: PAnsiChar'
[Warning] Unit2.pas(138): Unsafe type 'PCha1: PAnsiChar'
[Warning] Unit2.pas(139): Unsafe code 'FreeMem'
[Warning] Unit2.pas(139): Unsafe type 'PCha1: PAnsiChar' 編譯時會出現:
Project MDIAPP.exe raised exception class EVariantTypeCastError with message'Could not convert variant of type (OleStr) into type (Boolean)' 程式碼如下:
procedure TForm2.DBEdit8Change(Sender: TObject);
begin
form1.adoQuery2.Active:=True;
if form1.adoQuery2.Locate('PM5D1',form1.adoQuery1.FieldByName('A11').Value,[]) and
form1.adoQuery1.FieldByName('A12').Value <> form1.adoQuery2.FieldByName('PM5D2').Value then
form1.adoQuery1.FieldByName('A12').Value := form1.adoQuery2.FieldByName('PM5D2').Value;
end;
end.
|
ha0009
版主 發表:16 回覆:507 積分:639 註冊:2002-03-16 發送簡訊給我 |
你好:
if form1.adoQuery2.Locate('PM5D1',form1.adoQuery1.FieldByName('A11').Value,[]) and
(form1.adoQuery1.FieldByName('A12').Value <> form1.adoQuery2.FieldByName('PM5D2').Value) then
form1.adoQuery1.FieldByName('A12').Value := form1.adoQuery2.FieldByName('PM5D2').Value; 注意到我改哪裡了嗎< > 你需要在各個判斷式中加入括號< >
|
jawtair
一般會員 發表:30 回覆:92 積分:24 註冊:2003-04-26 發送簡訊給我 |
改成
procedure TForm2.DBEdit8Change(Sender: TObject); begin if form1.adoQuery2.Locate('PM5D1',form1.adoQuery1.FieldByName('A11').Value,[]) and (form1.adoQuery1.FieldByName('A12').Value <> form1.adoQuery2.FieldByName('PM5D2').Value) then (form1.adoQuery1.FieldByName('A12').Value := form1.adoQuery2.FieldByName('PM5D2').Value); end; end.後Compiler沒有問題,也可以執行,但當在郵遞區號A11輸入編號時,並沒有任何動作傳回,請問遺漏了那邊嗎? |
ha0009
版主 發表:16 回覆:507 積分:639 註冊:2002-03-16 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |