Ash Gudi

Ash Gudi

  • NA
  • 1
  • 1.8k

Invalid database rows returned

Aug 5 2010 3:27 PM

Hi Guys,
        I have just started to use ASP.net and was struck with the following lines of code. Basically i am trying to implement the login page. What i need to do is to compare the userinput against the username in the database and if it matches to a particular string called Ashwin then redirect him to the admin page.
However that is not happening. When i tried to debug the program using breakpoint what i have realized is the database is returning -1 for the RecordsAffected property.
My database is a simple table with two columns, userName and password. Pls help. Code is given belwo.
 
string
loginSt = "Select * from userDetails where userName = '" + TxtUser.Text + "'";
loginSt +=
"AND" + " " + "password = '" + TxtPwd.Text + "'";
SqlConnection con = new SqlConnection(connectionString);
SqlCommand cmd = new SqlCommand(loginSt, con);
SqlDataReader reader;
try
{
con.Open();
reader = cmd.ExecuteReader();

reader.Read();


if ( reader.GetString(0) == "Ashwin")
{
Response.Redirect(
"AdminPage.aspx");
}
else
{
Response.Redirect(
"About.aspx");
}

Answers (1)