Click here to Skip to main content
14,383,080 members
Rate this:
Please Sign up or sign in to vote.
See more:
hi



using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;

public partial class Login : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Button_Login_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["RegistrationConnectionString"].ConnectionString);
con.Open();
string checkuser = "select count(*) from UserData where [User Name]='" + TextBoxUserName.Text + "'";
SqlCommand com = new SqlCommand(checkuser, con);
int temp = Convert.ToInt32(com.ExecuteScalar().ToString());
con.Close();
if (temp == 1)
{
con.Open();
string checkPasswordQuery = "select password from UserData where [User Name]'" + TextBoxUserName.Text + "'";
SqlCommand passCom = new SqlCommand(checkPasswordQuery, con);
string password = passCom.ExecuteScalar().ToString().Replace(" ","");
if (password == TextBoxPassword.Text)
{
Session["New"] = TextBoxUserName.Text;
Response.Write("Password is correct");
Response.Redirect("Mnager.aspx");
}
else
{
Response.Write("Password is not correct");
}
}
}
}
Posted
Comments
King Fisher 1-Mar-14 1:27am
   
getting error?
harshavardhan12345678 1-Mar-14 1:32am
   
s no error
butdoen'tconnect to database connection
King Fisher 1-Mar-14 2:51am
   
use try catch block to catch the exception ,and update with exception info.
Rate this:
Please Sign up or sign in to vote.

Solution 1

con.Open();
string checkuser = "select count(*) from UserData where [User Name]='" + TextBoxUserName.Text + "'";
SqlCommand com = new SqlCommand(checkuser, con);
SqlDatareader dr = com.executereader();
if(dr.read())
{
int temp = dr[0];
}
con.Close();



this will work fine
   
Comments
harshavardhan12345678 1-Mar-14 1:40am
   
getting errors....



Error 1 The type or namespace name 'SqlDatareader' could not be found (are you missing a using directive or an assembly reference?) C:\Users\MR002\Documents\Visual Studio 2010\WebSites\LoginWebsite1\Login.aspx.cs 22 9 C:\...\LoginWebsite1\
Error 2 'System.Data.SqlClient.SqlCommand' does not contain a definition for 'executereader' and no extension method 'executereader' accepting a first argument of type 'System.Data.SqlClient.SqlCommand' could be found (are you missing a using directive or an assembly reference?) C:\Users\MR002\Documents\Visual Studio 2010\WebSites\LoginWebsite1\Login.aspx.cs 22 32 C:\...\LoginWebsite1\
Error 3 The name 'temp' does not exist in the current context C:\Users\MR002\Documents\Visual Studio 2010\WebSites\LoginWebsite1\Login.aspx.cs 28 13 C:\...\LoginWebsite1\
Tom Marvolo Riddle 1-Mar-14 1:50am
   
try this:
SqlCommand com = new SqlCommand(checkuser, con);
SqlDataReader dr = com.ExecuteReader();
harshavardhan12345678 1-Mar-14 1:53am
   
error is ===Invalid OPeration Exception was Unhandle by user code


There is already an open DataReader associated with this Command which must be closed first.
harshavardhan12345678 1-Mar-14 2:14am
   
There is already an open DataReader associated with this Command which must be closed first
Tom Marvolo Riddle 1-Mar-14 2:41am
   
which line?
harshavardhan12345678 1-Mar-14 3:01am
   
Line 20: string checkuser = "select count(*) from UserData where [User Name]='" + TextBoxUserName.Text + "'";
Line 21: SqlCommand com = new SqlCommand(checkuser, con); SqlDataReader dr = com.ExecuteReader();
Line 22: int temp = Convert.ToInt32(com.ExecuteScalar().ToString());
Line 23: con.Close();
Line 24: if (temp == 1)
Rate this:
Please Sign up or sign in to vote.

Solution 2

I think your code is correct .Do one thing
Debugg ur code line by line (f11) ,then copy the Checkuser value and run directly from the Sql server.....
   
Comments
harshavardhan12345678 1-Mar-14 2:16am
   
There is already an open DataReader associated with this Command which must be closed first
Rate this:
Please Sign up or sign in to vote.

Solution 3

Check whether namespace-- using system.data.sqlclient is added up in namespace or not.....if not...add them
   
Comments
harshavardhan12345678 1-Mar-14 3:33am
   
already added

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100