954,580 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Please help with login page code behind

Hello everyone,

I just started working with .net and need to create a simple login page. I have the design page but am struggling with the code behind. This is what I have so far. Alot of it is what I got from samples over the net. Below are the errors I'm getting when compiling it. I am not familiar with the commands for sqlclient so am not able to figure out what is wrong here. Any help would be appreciated.

Thanks,
Kathy

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
 
publicpartialclassCodeBehind : System.Web.UI.Page
{
public System.Web.UI.WebControls.Label Message;
public System.Web.UI.HtmlControls.HtmlTable tblSignIn;
public System.Web.UI.WebControls.TextBox UserName;
public System.Web.UI.WebControls.RequiredFieldValidator RFVLogin;
public System.Web.UI.WebControls.TextBox Password;
public System.Web.UI.WebControls.RequiredFieldValidator RFVPassword;
public System.Web.UI.WebControls.Button btnSignIn;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
// Display welcome message
Message.Text = "Enter Login and Password";
}
}
protected void btnSignIn_Click(Object obj, EventArgs e)
{
if(Page.IsValid)
{
// check username/password against a database table
System.Data.SqlClient.SqlConnection SQLCon = new
System.Data.SqlClient.SqlConnection("server=localhost;database=aspnetdb");
// get row back based on username/password
//System.Data.SqlClient.SqlDataAdapter System.Data.SqlClient.SqlDataAdapter("Select * From Person Where Username='" +
UserName.Text + "' And Password = '" +
Password.Text + "'");
System.Data.DataSet ds = new System.Data.DataSet();
SqlCmd.Fill( ds );
 
// check to see if the dataset contains no rows (if it is EOF (i.e.
// contains no rows), then the user is invalid)
if( ds.Tables["Person"].Rows.Count == 0 )
{
Message.Text = "Invalid User Name and Password. Try Again.";
} else {
Message.Text = "Congratulations!!! You have successfully signed in.";
}
}
}
}


*****Errors*****
'System.Data.SqlClient.SqlDataAdapter' is a 'type', which is not valid in the given context.

The name 'SqlCmd' does not exist in the current context.

kathy78
Newbie Poster
9 posts since Sep 2006
Reputation Points: 10
Solved Threads: 0
 

hi kathy,

There is an error in ur code if u notice.

System.Data.SqlClient.SqlDataAdapter SqlCmd=new System.Data.SqlClient.SqlDataAdapter("Select * From Person Where Username='" +
UserName.Text + "' And Password = '" +
Password.Text + "'");


SqlCmd.Fill( ds );


The error which u get

'System.Data.SqlClient.SqlDataAdapter' is a 'type', which is not valid in the given context.

explains that sqldataadapter is a type.u have not created an object for the type and the type sqldataadapter cannot be used as such.

Secondly,
The name 'SqlCmd' does not exist in the current context.

U have used SqlCmd here but u have not delcared it.

Hope you understand.

Thanks

Regards

Exelio

Exelio
Junior Poster in Training
57 posts since Aug 2006
Reputation Points: 10
Solved Threads: 0
 

Use parameters in SQL query, do not use direct insertion in query.

ManicCW
Junior Poster in Training
95 posts since Nov 2005
Reputation Points: 13
Solved Threads: 11
 
hi kathy, There is an error in ur code if u notice. System.Data.SqlClient.SqlDataAdapter SqlCmd=new System.Data.SqlClient.SqlDataAdapter("Select * From Person Where Username='" + UserName.Text + "' And Password = '" + Password.Text + "'"); SqlCmd.Fill( ds ); The error which u get 'System.Data.SqlClient.SqlDataAdapter' is a 'type', which is not valid in the given context. explains that sqldataadapter is a type.u have not created an object for the type and the type sqldataadapter cannot be used as such. Secondly, The name 'SqlCmd' does not exist in the current context. U have used SqlCmd here but u have not delcared it. Hope you understand. Thanks Regards Exelio





Thanks for all your help Exelio!

kathy78
Newbie Poster
9 posts since Sep 2006
Reputation Points: 10
Solved Threads: 0
 

Thanks for all your help...

kathy78
Newbie Poster
9 posts since Sep 2006
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You