Hay guys I'm new to programing and I'm making a sample app with user authentication. the database is connected and all working fine except for when I try to fetch the user Role from DB at login this error pops up System.IndexOutOfRangeException: 'Cannot find column 7.'
I have also tried: Role = dt.Rows[0]["Role"].ToString();
here's the code:
DataTable dt = new DataTable();
sda.Fill(dt);
if (dt.Rows[0][0].ToString() == "1")
{
Role = dt.Rows[0][7].ToString(); //Error comes on this line
if (Role == "Admin")
{
this.Hide();
Admin ss = new Admin();
ss.Show();
}
else
{
this.Hide();
Main ss = new Main();
ss.Show();
}
}
else
{
MessageBox.Show("Incorrect Username or Password.");
}
}