Click here to Skip to main content
15,896,464 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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.

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
 
Share this answer
 
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?
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.....
 
Share this answer
 
Comments
harshavardhan12345678 1-Mar-14 2:16am    
There is already an open DataReader associated with this Command which must be closed first
Check whether namespace-- using system.data.sqlclient is added up in namespace or not.....if not...add them
 
Share this answer
 
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, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900