By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,670 Members | 1,516 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,670 IT Pros & Developers. It's quick & easy.

Session & login/validating/ problem HELP

P: n/a
I have a code below.(It validates against a SQL DB(login page).thats is
giving me an error!
When i try to use :- Session["name"] = dr["username.Text"].ToString();
To catch the username so as to redirect the user logged in to another
page....PRINTING
Hello:- John .. for example

It says ERROR:- System.IndexOutOfRangeException: username.Text
What does this mean and how can i correct it
PLS HELP!!
Thx
void Login_Click(Object sender, EventArgs e)
{

SqlDataReader dr;

SqlConnection cn = new SqlConnection("Data Source=(local);Initial
Catalog=Northwind;Integrated Security=SSPI;");

cn.Open();

SqlCommand cmdQuestion = new SqlCommand("SELECT Password FROM Users WHERE
username = '" + username.Text + "'", cn);

dr=cmdQuestion.ExecuteReader();

if(dr.Read())

if(dr["Password"].ToString() == Password.Text)
// CookieAuthentication.RedirectFromLoginPage(Email.T ext, false);
Response.Redirect("testlabel.aspx");

else
Msg.Text = "Invalid password.";
else
Msg.Text = "Email address not found.";
//Session["name"] = dr["username.Text"].ToString();
cn.Close();


}

Nov 18 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Maybe dr["username.Text"] should be dr[username.Text] ?

--
Fadi El-Eter, itoctopus - http://www.itoctopus.com
"Patrick.O.Ige" <pa********@acn.waw.pl> wrote in message
news:e8**************@TK2MSFTNGP11.phx.gbl...
I have a code below.(It validates against a SQL DB(login page).thats is
giving me an error!
When i try to use :- Session["name"] = dr["username.Text"].ToString();
To catch the username so as to redirect the user logged in to another
page....PRINTING
Hello:- John .. for example

It says ERROR:- System.IndexOutOfRangeException: username.Text
What does this mean and how can i correct it
PLS HELP!!
Thx
void Login_Click(Object sender, EventArgs e)
{

SqlDataReader dr;

SqlConnection cn = new SqlConnection("Data Source=(local);Initial
Catalog=Northwind;Integrated Security=SSPI;");

cn.Open();

SqlCommand cmdQuestion = new SqlCommand("SELECT Password FROM Users WHERE
username = '" + username.Text + "'", cn);

dr=cmdQuestion.ExecuteReader();

if(dr.Read())

if(dr["Password"].ToString() == Password.Text)
// CookieAuthentication.RedirectFromLoginPage(Email.T ext, false);
Response.Redirect("testlabel.aspx");

else
Msg.Text = "Invalid password.";
else
Msg.Text = "Email address not found.";
//Session["name"] = dr["username.Text"].ToString();
cn.Close();


}

Nov 18 '05 #2

P: n/a
Hi patrick

Session["name"] = username.Text;

this wil work.

if you note, u r not selecting the username in your query and u r trying to
access it incorrectly.

--
Cheers!
Rajiv. R
Rajspace.Org

"Patrick.O.Ige" <pa********@acn.waw.pl> wrote in message
news:e8**************@TK2MSFTNGP11.phx.gbl...
I have a code below.(It validates against a SQL DB(login page).thats is
giving me an error!
When i try to use :- Session["name"] = dr["username.Text"].ToString();
To catch the username so as to redirect the user logged in to another
page....PRINTING
Hello:- John .. for example

It says ERROR:- System.IndexOutOfRangeException: username.Text
What does this mean and how can i correct it
PLS HELP!!
Thx
void Login_Click(Object sender, EventArgs e)
{

SqlDataReader dr;

SqlConnection cn = new SqlConnection("Data Source=(local);Initial
Catalog=Northwind;Integrated Security=SSPI;");

cn.Open();

SqlCommand cmdQuestion = new SqlCommand("SELECT Password FROM Users WHERE
username = '" + username.Text + "'", cn);

dr=cmdQuestion.ExecuteReader();

if(dr.Read())

if(dr["Password"].ToString() == Password.Text)
// CookieAuthentication.RedirectFromLoginPage(Email.T ext, false);
Response.Redirect("testlabel.aspx");

else
Msg.Text = "Invalid password.";
else
Msg.Text = "Email address not found.";
//Session["name"] = dr["username.Text"].ToString();
cn.Close();


}

Nov 18 '05 #3

P: n/a
Thx for the reply..it worked..
but when i use a username for example dog for the first time it works but
later when i use cat for example it keeps showing
Hello:- Dog..
It keeps DOG in the session for long.

But i want to ge the USERNAME from the datbase and display it
so it catches only yhe username from the DB only..

Help if u can..PLease..look at te code properly
Thx
"Rajiv R" <ra********************@yahoo.com> wrote in message
news:uJ**************@TK2MSFTNGP12.phx.gbl...
Hi patrick

Session["name"] = username.Text;

this wil work.

if you note, u r not selecting the username in your query and u r trying to access it incorrectly.

--
Cheers!
Rajiv. R
Rajspace.Org

"Patrick.O.Ige" <pa********@acn.waw.pl> wrote in message
news:e8**************@TK2MSFTNGP11.phx.gbl...
I have a code below.(It validates against a SQL DB(login page).thats is
giving me an error!
When i try to use :- Session["name"] = dr["username.Text"].ToString();
To catch the username so as to redirect the user logged in to another
page....PRINTING
Hello:- John .. for example

It says ERROR:- System.IndexOutOfRangeException: username.Text
What does this mean and how can i correct it
PLS HELP!!
Thx
void Login_Click(Object sender, EventArgs e)
{

SqlDataReader dr;

SqlConnection cn = new SqlConnection("Data Source=(local);Initial
Catalog=Northwind;Integrated Security=SSPI;");

cn.Open();

SqlCommand cmdQuestion = new SqlCommand("SELECT Password FROM Users WHERE username = '" + username.Text + "'", cn);

dr=cmdQuestion.ExecuteReader();

if(dr.Read())

if(dr["Password"].ToString() == Password.Text)
// CookieAuthentication.RedirectFromLoginPage(Email.T ext, false);
Response.Redirect("testlabel.aspx");

else
Msg.Text = "Invalid password.";
else
Msg.Text = "Email address not found.";
//Session["name"] = dr["username.Text"].ToString();
cn.Close();


}


Nov 18 '05 #4

P: n/a
Can anybody hellp with the Session question!!!
"Patrick.O.Ige" <pa********@acn.waw.pl> wrote in message
news:u6**************@tk2msftngp13.phx.gbl...
Thx for the reply..it worked..
but when i use a username for example dog for the first time it works but
later when i use cat for example it keeps showing
Hello:- Dog..
It keeps DOG in the session for long.

But i want to ge the USERNAME from the datbase and display it
so it catches only yhe username from the DB only..

Help if u can..PLease..look at te code properly
Thx
"Rajiv R" <ra********************@yahoo.com> wrote in message
news:uJ**************@TK2MSFTNGP12.phx.gbl...
Hi patrick

Session["name"] = username.Text;

this wil work.

if you note, u r not selecting the username in your query and u r trying

to
access it incorrectly.

--
Cheers!
Rajiv. R
Rajspace.Org

"Patrick.O.Ige" <pa********@acn.waw.pl> wrote in message
news:e8**************@TK2MSFTNGP11.phx.gbl...
I have a code below.(It validates against a SQL DB(login page).thats is giving me an error!
When i try to use :- Session["name"] = dr["username.Text"].ToString();
To catch the username so as to redirect the user logged in to another
page....PRINTING
Hello:- John .. for example

It says ERROR:- System.IndexOutOfRangeException: username.Text
What does this mean and how can i correct it
PLS HELP!!
Thx
void Login_Click(Object sender, EventArgs e)
{

SqlDataReader dr;

SqlConnection cn = new SqlConnection("Data Source=(local);Initial
Catalog=Northwind;Integrated Security=SSPI;");

cn.Open();

SqlCommand cmdQuestion = new SqlCommand("SELECT Password FROM Users WHERE username = '" + username.Text + "'", cn);

dr=cmdQuestion.ExecuteReader();

if(dr.Read())

if(dr["Password"].ToString() == Password.Text)
// CookieAuthentication.RedirectFromLoginPage(Email.T ext, false);
Response.Redirect("testlabel.aspx");

else
Msg.Text = "Invalid password.";
else
Msg.Text = "Email address not found.";
//Session["name"] = dr["username.Text"].ToString();
cn.Close();


}



Nov 18 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.