Re: [VB6 ] 修改後讀取資料庫

看板Visual_Basic作者 (什麼是真愛)時間19年前 (2006/03/31 22:50), 編輯推噓8(808)
留言16則, 2人參與, 最新討論串2/2 (看更多)
※ 引述《qos (什麼是真愛)》之銘言: : 存在視窗A和視窗B : 視窗A是用來修改資料庫的資料 : 視窗B是用來查詢資料庫的資料 : 問題: : 若我在視窗B查詢某一筆資料庫的資料 : 然後顯示在TextBox : 然後在視窗A更改這一筆資料 : 然後再一次在視窗B查詢這筆資料 : 資料卻還是舊的 : 除非我把視窗B關掉然後重開 : 才會查詢到新更新的資料 : 這是為什麼呢 : 我有設斷點去看我從資料庫讀出的資料是舊的 : 除非我重開B視窗 從資料庫讀出的資料才會是新的 : 這是為什麼呢 修改視窗的原始碼: Private Sub Command1_Click() Dim modify As Boolean modify = False Adodc1.Recordset.MoveFirst While (Not Adodc1.Recordset.EOF And Not modify) If Adodc1.Recordset.Fields(0) = Text1.Text Then Text2.Text = Adodc1.Recordset.Fields(0) If Adodc1.Recordset.Fields(1) <> "" Then Text3.Text = Adodc1.Recordset.Fields(1) End If If Adodc1.Recordset.Fields(2) <> "" Then Text4.Text = Adodc1.Recordset.Fields(2) End If MsgBox "欲修改之資料已於下方顯示!!!", , "提示訊息" modify = True End If Adodc1.Recordset.MoveNext Wend If Not modify Then MsgBox "欲修改之資料不存在!!!", , "錯誤訊息" Else Adodc1.Recordset.MovePrevious End If End Sub Private Sub Command2_Click() ret = MsgBox("是否真得要修改?", vbYesNo, "確認修改") If ret = vbYes Then Adodc1.Recordset.Fields(0) = Text2.Text Adodc1.Recordset.Fields(1) = Text3.Text Adodc1.Recordset.Fields(2) = Text4.Text Adodc1.Recordset.Update MsgBox "修改成功!!!", , "修改成功" End If End Sub 查詢視窗的原始碼: Private Sub Command1_Click() Dim inquire As Boolean inquire = False Adodc1.Recordset.MoveFirst While (Not Adodc1.Recordset.EOF And Not inquire) If Adodc1.Recordset.Fields(0) = Text1.Text Then Text2.Text = Adodc1.Recordset.Fields(0) If Adodc1.Recordset.Fields(1) <> "" Then Text3.Text = Adodc1.Recordset.Fields(1) End If If Adodc1.Recordset.Fields(2) <> "" Then Text4.Text = Adodc1.Recordset.Fields(2) End If inquire = True End If Adodc1.Recordset.MoveNext Wend If Not inquire Then MsgBox "欲查詢之資料不存在!!!", , "錯誤訊息" Else MsgBox "欲查詢之資料已於下方顯示!!!", , "提示訊息" End If End Sub -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 61.62.42.26

03/31 23:36, , 1F
沒看到你對Adodc1.Recordset 的定義- -
03/31 23:36, 1F

03/31 23:37, , 2F
如果是在屬性欄處定義~~那妳早將此Adodc1.Recordset抓出
03/31 23:37, 2F

03/31 23:43, , 3F
當然就還是顯示舊的資訊了~
03/31 23:43, 3F

03/31 23:45, , 4F
如果只選用Adodc1.Recordset的方法 應要技巧性的迴避
03/31 23:45, 4F

03/31 23:46, , 5F
二個表單同一時間被打開
03/31 23:46, 5F

03/31 23:46, , 6F
其實可以把 查詢及修改寫在同一個表單上面.這是最簡單的
03/31 23:46, 6F

04/02 16:41, , 7F
我是使用你說的第一個方式...如果還是想寫在兩個表單...請問
04/02 16:41, 7F

04/02 16:42, , 8F
可以如何解決
04/02 16:42, 8F

04/04 03:43, , 9F
..不是有說了= = 技巧性的去迴避他吧~~強迫使用者無法
04/04 03:43, 9F

04/04 03:45, , 10F
同時開啟二個表單。 或是在click的程式碼裡去定義adodc
04/04 03:45, 10F

04/05 14:01, , 11F
請問可以教導第二個方法怎麼用嗎?在VB裡子視窗被關閉會送出什
04/05 14:01, 11F

04/05 14:02, , 12F
麼訊息給父視窗?
04/05 14:02, 12F

04/06 03:17, , 13F
第二個方法= ="???
04/06 03:17, 13F

04/06 03:30, , 14F
在程式執行的時候,才去定義ADODC的ConnectionString
04/06 03:30, 14F

04/06 03:42, , 15F
就可以解決你的問題才是??
04/06 03:42, 15F

04/06 03:44, , 16F
愕~應該是說在Command_Click才去定義ConnectionString
04/06 03:44, 16F
文章代碼(AID): #14BK6onK (Visual_Basic)
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 2 篇):
文章代碼(AID): #14BK6onK (Visual_Basic)