I am getting this error on my login form. I am unsure on fixing it because I do not know what's wrong.
InvalidOperationException: no current row
When I start the app, it crashes.
private void buttonLogin_Click(object sender, EventArgs e)
{
SQLiteConnection conn = new SQLiteConnection("data source = zivali_v2.sqlite");
conn.Open();
SQLiteCommand com = new SQLiteCommand(conn);
com.CommandText = "SELECT * FROM login;";
SQLiteDataReader reader = com.ExecuteReader();
string username = reader["username"].ToString();
string password = reader["password"].ToString();
bool loginValid = false;
while (reader.Read())
{
if (username == textBoxUserName.Text && password == textBoxPassword.Text)
{
loginValid = true;
break;
}
}
if (loginValid)
{
MessageBox.Show("OK");
}
else
{
MessageBox.Show("Wrong username or password");
}
conn.Close();
}