尝试读取MySQL数据库时,我在VB.NET中遇到ExecuteReader()
问题。
这是代码。我把停靠点放在代码不工作的地方。没有错误,但它没有通过MyReader = MyComm.ExecuteReader()
。
Private Sub Load_Contact()
On Error GoTo Load_Contact_Error
Dim MyReader As MySqlDataReader
Dim MyConn As MySqlConnection = New MySqlConnection
Dim MyComm As MySqlCommand
Dim SQLstr As String
'Dim ThisDay As Date
Dim X As Integer
Dim BCount As Integer
'Dim Color_Count As Integer
MyConn.ConnectionString = ConnString
SQLstr = "SELECT * FROM contact WHERE User=?user AND DATE(ContactDate)= CURDATE();"
Stop
X = 1 'use to count the rows
Dim ISComplete As String
Stop
MyComm = New MySqlCommand(SQLstr, MyConn)
Stop
MyComm.Parameters.AddWithValue("?user", User)
Stop
MyReader = MyComm.ExecuteReader()
Stop
While MyReader.Read
BCount = BCount + 1
'Label5.Caption = "Loading reminders " & Format(BCount, "##,###")
'frmCount.Label1.Caption = "Loading reminders " & Format(BCount, "##,###")
If MyReader.Item("complete") = 1 Then
DataGridView4.Rows(X).DefaultCellStyle.BackColor = Color.Azure
ISComplete = "Yes"
Else
ISComplete = "No"
End If
Stop
DataGridView4.Rows.Add(MyReader.Item("Acct"), MyReader.Item("name"), MyReader.Item("Action"), MyReader.Item("Comment"), _
MyReader.Item("contactdate"), MyReader.Item("createdby"), ISComplete, MyReader.Item("id"))
X = X + 1
End While
Stop
MyReader.Close()
MyConn.Close()
MyConn.Dispose()
Exit Sub
Load_Contact_Error:
MsgBox("Load_Contact_Error ")
LogInfo = "Load_Contact_Error " & Err.Description
Call ErrorLogger()
End Sub
几个查询试图查看它是否是它不起作用的原因,这就是为什么你看到不止一个。我在查询编辑器中通过它们,它们都运行良好。 提前致谢