好日子:)vb.NET:文本框TextChange
我有一個文本框的參考號,收款人,辦公室和地址......一個程序我想的是,如果在義務表中存在參考號碼它會自動把收款人,辦公室和地址,如果沒有,你會鍵入收款人的名字,但如果存在Payees表中自動它會把辦公室和地址...
我的問題是,它顯示正確的結果,但一個消息框說「數據讀取器中沒有當前查詢」。我認爲代碼重疊,但我不知道如何解決這個問題。
這裏是我的txtRefNo.Text代碼:
Private Sub txtRefNo_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtRefNo.TextChanged
Try
modGlobalFunctions.Connection.Close()
modGlobalFunctions.connectDatabase()
Reader = modGlobalFunctions.executeQuery("SELECT DISTINCT ref_no, payee from bims_obligations " & _
"WHERE ref_no = '" & txtRefNo.Text & "'")
If Reader.HasRows Then
While Reader.Read
txtPayee.Text = Reader("payee").ToString()
txtOffice.Text = Reader("office").ToString()
txtAddress.Text = Reader("address").ToString()
txtPayee.Enabled = False
txtOffice.Enabled = False
txtAddress.Enabled = False
certALoadGrid()
End While
Else
txtPayee.Clear()
txtOffice.Clear()
txtAddress.Clear()
txtPayee.Enabled = True
txtOffice.Enabled = True
txtAddress.Enabled = True
End If
Reader.Close()
modGlobalFunctions.Connection.Close()
Catch ex As Exception
MessageBox.Show(ex.Message, "BIMS", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
modGlobalFunctions.Connection.Close()
End Sub
和txtPayee.text:
Private Sub txtPayee_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtPayee.TextChanged
Try
modGlobalFunctions.Connection.Close()
modGlobalFunctions.connectDatabase()
Reader = modGlobalFunctions.executeQuery("SELECT * from bims_payee " & _
"WHERE payee = '" & txtPayee.Text & "'")
If Reader.HasRows Then
While Reader.Read
txtOffice.Text = Reader("office").ToString()
txtAddress.Text = Reader("address").ToString()
End While
Else
txtOffice.Clear()
txtAddress.Clear()
End If
Reader.Close()
modGlobalFunctions.Connection.Close()
Catch ex As Exception
MessageBox.Show(ex.Message, "BIMS", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
modGlobalFunctions.Connection.Close()
End Sub
期待答案...或者是有一個如果要是引用號存在,那麼聲明它會忽略txtPayee的textChange?上帝保佑:)
這是*不錯*錯誤處理。你捕捉任何異常,只顯示消息,然後丟棄堆棧跟蹤和任何內部異常。處理特定的異常通常要好得多,因爲你有一個本地策略來處理異常,並讓其他異常傳遞給一個全局異常處理程序,這個異常處理程序將記錄所有的細節,然後終止你的進程。 –
對不起,我不擅長編程......我真的不明白你在說什麼...... :(幫助!:) – bayan0926
我不同意Damien_The_Unbeliever。如果您按照他的建議處理錯誤,用戶將會丟失所有輸入的數據。 – SSS