我逐步浏览了这段代码,发现该函数不仅从未被调用,而且 myBase.Load 的其余部分也从未完成这里发生的事情。
现在显示所有外部参考。程序永远不会碰到 ** 中的行,并且确实将 frmMain_Load 作为第一项运行。stepthrough 图标确实落在以 reader= 开头的行上,但从不调用 runAsIsQuery (断点不会捕获并且 stepthrough 会消失)。然后它向我显示 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)
**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
连接字符串类调用(MotorcyleDB)
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