-4

i am trying to get single value from sqlite database but i am facing error

so i can do some action to this value or check it

a busy cat

dbConnection StartConn = new dbConnection();
            SQLiteConnection MyConnetion = StartConn.GetConnection();

            SQLiteCommand Cm = new SQLiteCommand(" select * from Users where user_username = '" + txtBxUserName.Text + "' and user_password = '" + txtBxPassword.Text + "'", MyConnetion);

            MyConnetion.Open();
            SQLiteDataReader dr = Cm.ExecuteReader();
            dr.Read();

            int count = Convert.ToInt32(Cm.ExecuteScalar());

            if (count != 0)
            {
                globalVariables.userFullName = dr["user_name"].ToString();
                globalVariables.appLoginUser = dr["user_username"].ToString();
                globalVariables.appPasswordUser = dr["user_password"].ToString();
                globalVariables.userPermissions = dr["user_permissions"].ToString();

                mainForm newMainForm = new mainForm();
                newMainForm.Show();
                this.Hide();

                MyConnetion.Close();

1 Answers1

0

Your dtareader has no rows, and thats causes the error. try it like this:

if(dr.Read())
{
    // rest of your code
}
Ashkan Mobayen Khiabani
  • 33,575
  • 33
  • 102
  • 171