Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

rows.count property not working 2

Status
Not open for further replies.

CRuser89

Programmer
May 18, 2005
79
US
Hello everyone,

Please see the line in bold below. I am trying to redirect the user to the Default.aspx page if the query from the typed data set (Criteria) returns at least a row. However, I am putting in usernames and passwords that do not exist in the 'People' table and it still goes true and redirects to the Default.aspx page. I know that the query works because I have tested it out. Either way, if I enter in a valid login account or invalid login account it is coming back true. If I put in > 1 instead of > 0 then it would redirect me to the SignInError.aspx. I dont' know why it's counting an invalid entry as one row. Am I doing something wrong? Please help. Thank you.

Kathy


code behind
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Web.Security;
using System.Data.SqlClient;
using System.Configuration;
using LoginInfoTableAdapters;


namespace LoginTest
{

public partial class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox UserName;
protected System.Web.UI.WebControls.RequiredFieldValidator rvUserValidator;
protected System.Web.UI.WebControls.TextBox Password;
protected System.Web.UI.WebControls.RequiredFieldValidator rvPasswordValidator;
protected System.Web.UI.WebControls.Button cmdSubmit;
protected System.Web.UI.WebControls.ValidationSummary Validationsummary1;
protected System.Web.UI.WebControls.Label lblMessage;
protected System.Web.UI.WebControls.Label lblMessage2;

private void Page_Load(object sender, System.EventArgs e)
{

}

protected void cmdSubmit_Click(object sender, System.EventArgs e)
{

string UserName = string.Empty;
string Password = string.Empty;

UserName = ((TextBox)Login1.FindControl("UserName")).Text;
Password = ((TextBox)Login1.FindControl("Password")).Text;

if (Page.IsValid)
{
tblPeopleTableAdapter LoginAdapter = new tblPeopleTableAdapter();

LoginInfo.tblPeopleDataTable Criteria =
LoginAdapter.GetDataBy(UserName, Password);



// Redirect if we succeeded


if (Criteria.Rows.Count > 0)
{
Response.Redirect("Default.aspx");
}
else
{
Response.Redirect("SignInError.aspx");
}
}

}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{

}
}
}

 
Have you stepped through the code?


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Hello ca8msn. Everything was working as expected until I added the if condition today. It still works but instead it redirects the user to the Default.aspx page regardless of correct or incorrect login. Is that what you were asking ca8msn? If not...sorry...
 
id look into the code thats here...

LoginInfo.tblPeopleDataTable Criteria = LoginAdapter.GetDataBy(UserName, Password);

are you sure what its returning?

LoginAdapter.GetDataBy("John","Doe")
Can equal this (still returning more than 0 rows)
row value
--- ------
1 null

 
What I mean, is have you stepped through the code, looked at the objects and see what they actually contain? My guess is that your data abject doesn't contain any rows but this is something you will have to find out yourself by debugging the project.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Thank you adamroof and ca8msn. It turns out that there was something wrong w/the query. It works fine now....thanks guys..
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top