Click here to Skip to main content
16,012,223 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi everyone,

If usertype is "admin" the datareader is not reading values from the table...
Can anybody help me with this??

Here is my code :

String username = TextBox1.Text.ToString();
String password = TextBox2.Text.ToString();
String utype = DropDownList1.Text.ToString();

if (utype == "user")
{
    SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["WATERMARKING"].ToString());
    String query = "Select USERNAME,PASSWORD,UTYPE from PROFILE where USERNAME='" + username + "'   and PASSWORD = '" + password + "' and UTYPE= '" + utype + "' ";
    SqlCommand cmd = new SqlCommand(query, cn);
    cn.Open();

    SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);

    reader.Read();
    if (reader.HasRows)
    {
        HttpContext.Current.ApplicationInstance.CompleteRequest();
        Response.Redirect(Session["URL"].ToString());
    }
    else
    {
        HttpContext.Current.ApplicationInstance.CompleteRequest();
        //Response.Redirect( "LOGIN.aspx"  ) ;
        String s = "invalid user  password or username";
        Response.Write(s);
    }
}

else if(utype=="admin")
{
    SqlConnection cnn = new SqlConnection(ConfigurationManager.ConnectionStrings["WATERMARKING"].ToString());
    String queryy = "Select USERNAME,PASSWORD from PROFILE where USERNAME='" + username + "'   and PASSWORD = '" + password + "' ";
    SqlCommand cmd = new SqlCommand(queryy, cnn);
    cnn.Open();

    SqlDataReader readerr = cmd.ExecuteReader(CommandBehavior.CloseConnection);

    readerr.Read();
    if (readerr.HasRows)
    {
        HttpContext.Current.ApplicationInstance.CompleteRequest();
        Response.Redirect(Session["URLL"].ToString());
        //Response.Write("helo");
    }
    else
    {
        //HttpContext.Current.ApplicationInstance.CompleteRequest();
        //Response.Redirect( "LOGIN.aspx"  ) ;
        String s = "invalid admin password or username";
        Response.Write(s);
    }
}
Posted
Updated 22-Jan-11 2:10am
v2
Comments
Richard MacCutchan 22-Jan-11 8:17am    
Add some error checking code to try and see what values you are getting. Or run it through the debugger and check that things are working as expected.
RKT S 22-Jan-11 8:19am    
everything is working fine..the only problem is when usertype is admin..reader returns a null value...
Yusuf 22-Jan-11 8:30am    
check your data. If you run the query on SQL Server outside your code, what do you get?

1 solution

Are you sure that DropDownList1 value is changing to "admin" ?I hope you have put debugger & confirmed that value is getting changed to admin & the actual problem is with reader.Also,your query,I dont see utype being passed for admin.Is that not required for this?
String queryy = "Select USERNAME,PASSWORD from PROFILE where USERNAME='" + username + "'   and PASSWORD = '" + password + "' ";
 
Share this answer
 
Comments
Sandeep Mewara 22-Jan-11 13:09pm    
Good suggestion!
Anupama Roy 23-Jan-11 3:29am    
Thanks Sandeep!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900