I have the following code for a login winform. When I make the connection to the database and make a select statement I get no rows back. I'm getting the message "No data exists for the row/column."
But there are rows and columns in the database.
Can someone tell me what I do wrong?
Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
Dim connectionString As String = System.Configuration.ConfigurationManager.ConnectionStrings("MySqlConnectionString").ConnectionString
Using con As New OleDbConnection(connectionString)
Dim intResult As Integer = 0
' MsgBox(connectionString)
Try
con.Open()
Using cmd As New OleDbCommand("SELECT Gebruikersnaam FROM Gebruikers WHERE Gebruikers.Gebruikersnaam = @Username", con)
cmd.Parameters.AddWithValue("@Username", UsernameTextBox.Text)
cmd.Parameters.AddWithValue("@Password", PasswordTextBox.Text)
Using dr As OleDbDataReader = cmd.ExecuteReader()
'intResult = CInt(cmd.ExecuteScalar)
'If intResult > 0 Then
MsgBox(dr.Item("Gebruikersnaam").ToString)
'End If
With dr
While .Read()
MsgBox(.HasRows)
'MsgBox(.Item("Gebruikersnaam"))
'TextBox1.Text = .Item("Gebruikersnaam") & vbCrLf
End While
End With
End Using
End Using
Catch ex As Exception
MsgBox(ex.Message)
con.Close()
End Try
Me.Close()
End Using
End Sub