我很抱歉我的英语不好。我希望有人可以解释错误的The conversion from type MySqlDataReader to type Integer is invalid
含义。
我确信这是一个简单的'Dim a Integer,但它比这更大,或者我只是愚蠢。
我的 btnLogin_Click 代码:
Dim SQL As New MySQLHook
Dim loginResult As Integer
Dim User As TextBox = Me.Controls.Item("TextGebruikersNaam")
Dim Pass As TextBox = Me.Controls.Item("TextGebruikersPass")
If String.IsNullOrEmpty(User.Text) Or String.IsNullOrEmpty(Pass.Text) Then
MsgBox("Voer een gebruikersnaam en wachtwoord in om verder te gaan.", MsgBoxStyle.Exclamation, "Foutmelding")
User.Focus()
Else
loginResult = SQL.Results("SELECT * FROM tblgebruikers " & "WHERE GebruikersNaam='" & User.Text & "' AND " & "GebruikersPass='" & Pass.Text & "'")
If loginResult = 1 Then
' Login was good, todo: add code here
Else
MsgBox("De gebruikersnaam of wachtwoord is onjuist. Probeer het opnieuw of vraag een nieuw wachtwoord aan.", MsgBoxStyle.Exclamation, "Foutmelding")
User.Text = ""
Pass.Text = ""
User.Focus()
End If
End If
我的结果代码(SQL.Results 来自 As New MySQLHook)
Public Function Results(ByVal sql)
Try
Dim conn = Connect()
Dim myAdapter As New MySqlDataAdapter
Dim myCommand As New MySqlCommand()
myCommand.Connection = conn
myCommand.CommandText = sql
myAdapter.SelectCommand = myCommand
Dim myData As MySqlDataReader
myData = myCommand.ExecuteReader()
Return myData
Catch myerror As MySqlException
clsError.logMessage("De server retourneerde de volgende foutmelding: " & myerror.Message)
Return DBNull.Value
End Try
End Function
我也尝试使用此功能,但它给了我相同的错误消息:
Public Function num_results(ByVal sql)
Try
Dim conn = Connect()
Dim myAdapter As New MySqlDataAdapter
Dim myCommand As New MySqlCommand()
myCommand.Connection = conn
myCommand.CommandText = sql
myAdapter.SelectCommand = myCommand
Dim myData As MySqlDataReader
myData = myCommand.ExecuteReader()
Return myData
Catch myerror As MySqlException
clsError.logMessage("De server retourneerde de volgende foutmelding: " & myerror.Message)
Return DBNull.Value
End Try
End Function
为什么会弹出这个转换错误?我确信 1 或 0 是不言自明的。