我逐句通過此代碼,發現該函數不僅未被調用,而且myBase.Load的其餘部分從未完成此處發生的事情。mybase.load在調用函數時停止加載vb.net
現在顯示所有外部參考。程序不會擊中**中包圍的行,並且會將frmMain_Load作爲第一項運行。穿越圖標確實落在以讀者=開頭的行上,但從未調用runAsIsQuery(斷點不會被捕捉,並且穿行只會消失)。那麼就說明我frmMain未經frmMain_Load也不是來自runAsISQuery
Private Sub frmMain_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
sqlstring = "SELECT Nickname FROM tblBikeInfo"
reader = sql.runAsIsQuery(cnn, sqlstring) 'never fires
**If 1 = 1 Then**
'ummmm never comes back here either
End If
額外的細節要求瞭解的其他參考等待處理任何其他代碼,這些都在frmMain爲全局變量
Dim reader As OleDbDataReader
Dim sql As OLEDB_Handling 'custom class
Public cnn = MotorcyleDB.GetConnection
功能從自定義類(OLEDB_Handling )稱爲(MotorcyleDB)
**Public Function runAsIsQuery(connection As OleDbConnection, SQL As String) As OleDbDataReader**
Dim reader As OleDbDataReader
Dim command As New OleDbCommand(SQL)
command.Connection = connection
Try
connection.Open()
reader = command.ExecuteReader()
Return reader
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Function
連接字符串類
Public Shared Function GetConnection() As OleDbConnection
Return New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\************\Documents\Visual Studio 2010\Projects\MotorcycleMinder\MotorcycleMinder\MotorcycleServiceLog11.accdb")
End Function
您需要提供比我們更多的知識。如何創建讀者,如何創建sql,如何創建cnn,如果代碼放置在try catch塊中會發生什麼?您是否嘗試過使用RunQuery運行查詢? – WozzeC 2013-04-30 10:38:32
嘗試調用runAsIsQuery的行會生成異常。因爲你沒有異常處理,所以它正在退出。要麼繞過Try..Catch捕捉異常,要麼更改調試器的Break On設置。 – RBarryYoung 2013-04-30 21:05:46
好吧,我oledbexcpetion趕上我的本地副本,它似乎是不夠的。現在我把一個通用的捕獲它確實有效地趕上...現在我得到空ref參考例外..我可以處理..很好的經驗教訓。現在我可以向我的老教師展示這件事,我請求幫助(誰也不能回答),謝謝大家。 – Skwiggs 2013-05-01 01:29:55