Ok, I'm a newbie c# and SQL learner.
I have a login form that connects to a SQL Server database. It was working earlier on my VS 2010 (Adm_page form and main_page form were displaying) and today it stopped displaying just the IDE showing ready.
Here is the code:
String query = "Select Count(*) from Login where Username ='" + Usn_txt.Text + "'and Password ='" + Psw_txt.Text + "' and Mode ='" + comboBox1.Text + "';";
SqlConnection con = new SqlConnection(con_string);
SqlDataAdapter da = new SqlDataAdapter(query, con);
DataTable dt = new DataTable();
da.Fill(dt);
if (dt.Rows[0][0].ToString() == "1")
{
SqlDataAdapter da1 = new SqlDataAdapter("Select Mode from Login Where Username ='" + Usn_txt.Text + "'and Password ='" + Psw_txt.Text + "'", con);
DataTable dt1 = new DataTable();
da1.Fill(dt1);
if (dt1.Rows[0][0].ToString() == "Admin")
{
this.Hide();
Adm_page aa = new Adm_page(Usn_txt.Text);
aa.ShowDialog();
Usn_txt.Clear();
Psw_txt.Clear();
this.Show();
}
else if (dt1.Rows[0][0].ToString() == "Student")
{
Main_page mm = new Main_page();
mm.ShowDialog();
this.Hide();
Usn_txt.Clear();
Psw_txt.Clear();
this.Show();
}
}
else
{
MessageBox.Show("Username and Password Error");
}
As I said earlier, the form was displaying up till today when it stopped. I realised it had something to do with the nested if statement because when I run this only
String query = "Select Count(*) from Login where Username ='" + Usn_txt.Text + "'and Password ='" + Psw_txt.Text + "' and Mode ='" + comboBox1.Text + "';";
SqlConnection con = new SqlConnection(con_string);
SqlDataAdapter da = new SqlDataAdapter(query, con);
DataTable dt = new DataTable();
da.Fill(dt);
if (dt.Rows[0][0].ToString() == "1")
{
this.Hide();
Adm_page aa = new Adm_page(Usn_txt.Text);
aa.ShowDialog();
Usn_txt.Clear();
Psw_txt.Clear();
this.Show();
}
The form shows up.
Is there any other way I can solve this issue or bypass this. Please help me out?