Session & login/validating/ problem HELP

P

Patrick.O.Ige

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.Text, 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();






}
 
R

Rajiv R

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.
 
P

Patrick.O.Ige

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 said:
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 said:
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.Text, 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();






}
 
P

Patrick.O.Ige

Can anybody hellp with the Session question!!!


Patrick.O.Ige said:
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 said:
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 said:
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.Text, 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();






}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top