全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:1153
推到 Plurk!
推到 Facebook!

轉換郵遞區號並傳查詢值

尚未結案
jawtair
一般會員


發表:30
回覆:92
積分:24
註冊:2003-04-26

發送簡訊給我
#1 引用回覆 回覆 發表時間:2003-06-13 04:40:19 IP:61.221.xxx.xxx 未訂閱
這是我使用的元件結構 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

發送簡訊給我
#2 引用回覆 回覆 發表時間:2003-06-13 08:35:34 IP:218.16.xxx.xxx 未訂閱
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

發送簡訊給我
#3 引用回覆 回覆 發表時間:2003-06-14 16:50:08 IP:61.221.xxx.xxx 未訂閱
引言:
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;    
Justmade版主您好: 感謝您在百忙之中,抽空回答,關於您所提的解答,乍看來已了解寫法,但心中仍有些疑問如下:
  • 是否要另建立一新的ADOConnection,但Form1.ADOConnection1裡面的資料庫已保含pm3d及pm5d資料表
  • 或是另建一個新的ADOQuery,但我要如何指定到pm5d,我看了form1.ADOQuery1好像也沒指定pm3d,另我深感困惑
盼望版主或各位先見高手,能指導一番,謝謝。
jawtair
一般會員


發表:30
回覆:92
積分:24
註冊:2003-04-26

發送簡訊給我
#4 引用回覆 回覆 發表時間:2003-06-19 16:22:17 IP:61.221.xxx.xxx 未訂閱
試了好久, 仍然不行, 會出現錯誤訊息: [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

發送簡訊給我
#5 引用回覆 回覆 發表時間:2003-06-19 16:32:03 IP:61.30.xxx.xxx 未訂閱
你好: 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

發送簡訊給我
#6 引用回覆 回覆 發表時間:2003-06-20 20:41:59 IP:61.221.xxx.xxx 未訂閱
改成
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

發送簡訊給我
#7 引用回覆 回覆 發表時間:2003-06-20 22:45:45 IP:61.56.xxx.xxx 未訂閱
你好: 沒錯誤代表你的語法都正確囉< > 但卻不代表你的程式邏輯無誤< >所以檢查看看你帶入的值是否正確或是 DataSource 的設定有沒有設好,參考看看唄
系統時間:2024-06-02 0:03:59
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!