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

Session problems with LOGIN/Validating

P: n/a
I have a problem with the code below:-
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 get the USERNAME from the datbase and display it
so it catches only the username from the DB only..

I think 'm not placing the "Session["name"] = username.Text; "
CAN ANYBODY ADVICE WHERE I SHOULD PUT THE "SESSION"

Help if u can..PLease..look at the code properly
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"] = username.Text;
cn.Close();
}

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


P: n/a
if(dr["Password"].ToString() == Password.Text)
Session["name"] = username.Text;
// every time a new user is successfully matched, it is at that point
// that you want to store their entered username in Session.
"Patrick.O.Ige" <pa********@acn.waw.pl> wrote in message
news:O8****************@TK2MSFTNGP10.phx.gbl...
I have a problem with the code below:-
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 get the USERNAME from the datbase and display it
so it catches only the username from the DB only..

I think 'm not placing the "Session["name"] = username.Text; "
CAN ANYBODY ADVICE WHERE I SHOULD PUT THE "SESSION"

Help if u can..PLease..look at the code properly
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"] = username.Text;
cn.Close();
}

Nov 18 '05 #2

P: n/a
Thx for the advice..
but when i do:-it says error:-"Invalid attempt to read when no data is
present."
Can you help me with the code!!
Thx
if(dr["Password"].ToString() == Password.Text) {
Session["name"] = username.Text; }
// CookieAuthentication.RedirectFromLoginPage(Email.T ext, false);
Response.Redirect("testlabel.aspx");
// else Msg.Text = "Invalid password.";

if(dr.Read()) {
//else
}
Msg.Text = "Email address not found.";

//Session["name"] = username.Text;
//Session["name"] = dr["username.Text"].ToString();
//Session.Terminate();
cn.Close();
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #3

P: n/a
Hi Peter..
Well I did this(And its WORKING !!!! ):-
Thx mo!!U are the best in the FORUM!!

if(dr.Read()) if(dr["Password"].ToString() == Password.Text)
{
Session["name"] = username.Text;
// CookieAuthentication.RedirectFromLoginPage(Email.T ext, false);
Response.Redirect("testlabel.aspx");
}
else
Msg.Text = "Invalid password.";
else
Msg.Text = "Email address not found.";
cn.Close();


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.