473,473 Members | 1,975 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Session & login/validating/ problem HELP

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
4 1993
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Paul | last post by:
Hmmm, didn't seem to work. I have set session.use_cookies = 1 and session.use_trans_sid = 1 in my php.ini file. Index.php contains:...
2
by: wozza | last post by:
Hi I'm involved in quite a large project which has a slightly unusual form of login (at least I think it's unusual!). I'm creating a site in ASP (actually Chilisoft ASP) where access to all...
0
by: Billy Boone | last post by:
I have a current web application that utilizes a login to authenticate users into the application. Once I authenticate them, I store away the user's name in a Session variable. I then utilize...
1
by: Pete | last post by:
Hi, Hope one of you guys can help me. I've got a site that's been running just fine for the last couple of months that uses Forms Authentication. I have two methods of login on the site, a...
2
by: Tomk | last post by:
I'm using forms authentication in an ASP.NET application. If I am on a page that requires authentication and my session timesout I am returned to the login page. Isn't it supposed to take me back...
3
by: Carpe Diem | last post by:
Hello I have an aspx page that loses Session("user") value after a few minutes even after I set <sessionState mode="InProc" cookieless="false" timeout="300"> in web.config and wrote function...
3
by: Patrick.O.Ige | last post by:
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...
0
by: SeanGallavan | last post by:
Our Environment: Two network load balanced (using Microsoft NLB software) webservers with session maintained in a SQL Server database. NLB is configured with no affinity settings and two...
10
by: GreggTB | last post by:
I've got an page (LOGIN.ASPX) that receives the user's login information. During the page load, it checks the credentials against a database and, if validation is successful, creates an instance of...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.