Click here to Skip to main content
15,887,027 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: (untagged)
Respected Sir,

my following code is not working .
SqlConnection con = new SqlConnection("data source=Abhishek-PC;integrated security=true;initial catalog=easyschool;");
SqlCommand com = new  SqlCommand("select * from LoginUser", con);
con.Open();
if (con.State == ConnectionState.Open)
{
   SqlDataReader dtr;
    dtr = com.ExecuteReader();
    while (dtr.Read())
    {
        Session["UserId"] = TextBox1.Text;

        if(dtr[0].ToString().Equals(TextBox1.Text) && dtr[1].ToString().Equals(TextBox2.Text) && dtr[2].ToString().Equals(DropDownList1.SelectedValue))
        {
            //flag = 1;

            Response.Redirect("Home.aspx");
            //break;
        }
    }


In this code If loop of datareader is not executing.
Means if if condition would be true then only we will be redirected to the Home page.
But when we enter user name ,password and Role and while we click button we are on same page(means it does not redirect anywhere).

Before sometime it was working fine all of sudden it stopped working.

Pls help me out.

Thanks
Abhishek


[edit]Code block added, "Ignore HTML..." option disabled - OriginalGriff[/edit]
Posted
Updated 17-Jul-11 4:50am
v2

Run it through the debugger.
My guesses are that either you do not have the correct connection string causing con.Open(); to throw an exception - in that case if (con.State == ConnectionState.Open) will never be executed; or something strange has happened to your database.

Best regards
Espen Harlinn
 
Share this answer
 
Comments
abhiamity86 17-Jul-11 11:01am    
Thanks For reply..
But sir it was working fine before somedays
Espen Harlinn 17-Jul-11 11:07am    
That's why I'm making these guesses - try wrapping the code in a:
try
{
<your code goes here>
}
catch(Exception exc)
{
<Log exception to file here >
}

block ...
My friend.Try to debug your code first,or try to put a try catch statement.I see no error in your code,so maybe it is a connection issue.
 
Share this answer
 

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