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[[COLOR=#800000]"Person"[/COLOR]].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.

Recommended Answers

All 4 Replies

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

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

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!

Thanks for all your help...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.