Hi There. I have the following code for a login system withing VB 2010. I am getting a Warning: "Variable 'reader' is used before it has been assigned a value. A null reference exception could result at runtime." Where did I go wrong?
Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click
Dim cmd As New MySqlCommand
Dim User As String = txtUsername.Text
Dim Pass As String = txtPassword.Text
Dim reader As DataTableReader
connection.Open()
cmd.CommandText = "SELECT * FROM `users` WHERE Username= '" & txtUsername.Text & "' and Password= '" & txtPassword.Text & "', conn|"
cmd.Connection = connection
cmd.Parameters.Add(New MySqlParameter("?UserName", txtUsername.Text))
cmd.Parameters.Add(New MySqlParameter("?Password", txtPassword.Text))
cmd.Connection = connection
'cmd.EndExecuteReader = reader
If reader.HasRows() Then
MessageBox.Show("Login Success!", "Success!", MessageBoxButtons.OK, MessageBoxIcon.Information)
Form2.Show()
Me.Close()
Else
MsgBox("Invalid Login Information!", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
connection.Close()
End Sub
End Class