Re: [VB6 ] 修改後讀取資料庫
※ 引述《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
03/31 23:36, 1F
→
03/31 23:37, , 2F
03/31 23:37, 2F
推
03/31 23:43, , 3F
03/31 23:43, 3F
→
03/31 23:45, , 4F
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
04/04 03:45, 10F
推
04/05 14:01, , 11F
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
04/06 03:30, 14F
→
04/06 03:42, , 15F
04/06 03:42, 15F
推
04/06 03:44, , 16F
04/06 03:44, 16F
討論串 (同標題文章)
Visual_Basic 近期熱門文章
PTT數位生活區 即時熱門文章