login page not redirect to reports page in asp.net mysql
i try to login with usertype and redirect to their pages eg admin redirect to reports page and public user redirect to gallery..
when i try to login from admin username and password then nothing happened.. when click on login button page redirect login page and not redirect to reports page where as i want when admin login then they redirect to reports page
whereas when i login with public user name and password it redirect to gallery pages ..
here is the code
protected void Button1_Click1(object sender, EventArgs e)
{
name = TextBox1.Text.Trim();
pwd = TextBox2.Text.Trim();
conn.Open();
MySqlCommand cmd = new MySqlCommand("select ln.UName, ln.UPasword, ut.UserType_ID from login ln, UserType ut where ln.UName = '"
+ name + "' and ln.UPasword = '" + pwd
+ "' and ln.UserType_ID = ut.UserType_ID");
cmd.Connection = conn;
MySqlDataReader dr = cmd.ExecuteReader();
if ( dr.HasRows )
{
dr.Read( );
Session[ " UName" ] = dr[ 0 ].ToString( );
Session[ " UPasword" ] = dr[ 1 ].ToString( );
Session[ "UserType_ID" ] = dr[ 2 ].ToString( );
}
if (dr[2].ToString() == "1")
{
Response.Redirect( "View_Reports.aspx" );
}
else
{
Response.Redirect( "gallery.aspx" );
}
dr.Close();
conn.Close();
}
any help please?
As from you question it is clear that it is not going in if part.
Check the dr[2].ToString()
value in your code are you getting "1" for not.
You have also not used try
, catch
and finally
block in you code. Use them.
上一篇: 如何在C#中使用开关箱