Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: .NET
this is the code of login but it is not working can u please help me out...
 
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
 
public partial class sigin_in : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
   
    }
    SqlConnection con = new SqlConnection("Data Source=KRISHN-PC;Initial Catalog=sign;Persist Security Info=True;User ID=sa;Password=***********");
    protected void Button1_Click(object sender, EventArgs e)
    {
        SqlDataAdapter obj = new SqlDataAdapter("select from login where userid = '"+TextBox1.Text+"'and password = '"+TextBox2.Text +"'",con);
        DataSet a = new DataSet();
        obj.Fill(a);
        //obj.Update(a);
        if (a.Tables[0].Rows.Count > 0)
        {
            Response.Redirect("home.aspx");
        }
        else
        {
            Label.Text = " wrong pswd";
        }
    }
 
}
Posted 22-Jul-11 2:01am
Edited 22-Jul-11 12:24pm
thatraja238K
v2
Comments
digimanus at 22-Jul-11 8:16am
   
select from login where userid --> leads to error because no fields are defined
krishn2011 at 22-Jul-11 12:56pm
   
dear i have given the field = to "textbox1.text"
digimanus at 22-Jul-11 16:58pm
   
sql is something like select [fieldname] from login where.....
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

a SqlDataAdapter needs an Open() SqlConnection and after the data is in the dataset the SqlConnection needs to be Closed()
 
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
  
 public partial class sigin_in : System.Web.UI.Page
 {
	string connectToDB = "Data Source=KRISHN-PC;Initial Catalog=sign;Persist Security Info=True;User ID=sa;Password=***********";
	protected void Page_Load(object sender, EventArgs e)
	{
 
	}
 
	protected void Button1_Click(object sender, EventArgs e)
	{
		SqlConnection con = new SqlConnection(connectToDB);
		string myQuery = string.Format("select from login where userid = '{0}' and password = '{1}'", TextBox1.Text, TextBox2.Text);
		SqlDataAdapter obj = new SqlDataAdapter(myQuery, con);
		try
		{
			con.Open()
			DataSet a = new DataSet();
			obj.Fill(a);
			
			if (a.Tables[0].Rows.Count > 0)
			{
				Response.Redirect("home.aspx");
			}
			else
			{
				Label.Text = " wrong pswd";
			}
		}
		catch (Exception err)
		{
		}
		finally
		{
			if (null != con && con.Connection.State == ConnectionState.Open)
				con.Close();
		}
	 }
 } 
  Permalink  
v2
Comments
krishn2011 at 22-Jul-11 12:44pm
   
dear this is nt right..
digimanus at 22-Jul-11 16:57pm
   
explain please
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 6

Although this isn't a solution, I didn't want to add it as a plain comment, as I feel it is to important to go there.
 
Don't connect to any database using the sa account - also this account needs to be renamed to something else at least.
 
If you can't use integrated security then create a specific accounts for your database and make sure you grant the least amount of privaleges to each as possibly.
 
Have a google to learn more about securing your databases.
  Permalink  
Comments
digimanus at 22-Jul-11 9:32am
   
real good advice
krishn2011 at 22-Jul-11 12:58pm
   
yeah ..but we cant change the user name for your one program ...
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Try removing the ***** in password field of connection string and type actual password......hope it will work.
  Permalink  
Comments
digimanus at 22-Jul-11 8:14am
   
Something tells me he did not want to provide the password to us
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

You can use this code
SqlConnection con = new SqlConnection("Data Source=KRISHN-PC;Initial Catalog=sign;Persist Security Info=True;User ID=sa;Password=***********");
con.open();
string str=
SqlCommand cmd=new SqlCommand(select from login where userid = '"+TextBox1.Text+"'and password = '"+TextBox2.Text +"'",con);
SqlDataRaeder dr=cmd.ExecuteReader();
if(dr.Read())
{
Response.Redirect("home.aspx");
con.Close();
}
<else>
{
Label.Text = " wrong pswd"
con.Close();
}</else>
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

here u have to open the connection and give completed pwd instead of giving **
 
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
 
public partial class sigin_in : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
 
}
SqlConnection con = new SqlConnection("Data Source=KRISHN-PC;Initial Catalog=sign;Persist Security Info=True;User ID=sa;Password=giveurpwd");
con.Open();----------->Open connection
protected void Button1_Click(object sender, EventArgs e)
{
SqlDataAdapter obj = new SqlDataAdapter("select from login where userid = '"+TextBox1.Text+"'and password = '"+TextBox2.Text +"'",con);
DataSet a = new DataSet();
obj.Fill(a);
//obj.Update(a);
if (a.Tables[0].Rows.Count > 0)
{
Response.Redirect("home.aspx");
}
else
{
Label.Text = " wrong pswd";
}
}
 
} .
  Permalink  
Comments
digimanus at 22-Jul-11 8:26am
   
where is your connection closed? If you used a using() around the SqlConnection it was ok.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

Call the SqlConnection's Open method before passing it on to the SqlDataAdapter's constructor. SqlDataAdapter requires an open connection. And also specify the Column names in your select statement.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 7

Your SQL 'Select' statement does not provide any field name.
 
'Select from login where ........' is a invalid sql statement.
  Permalink  
Comments
krishn2011 at 22-Jul-11 12:43pm
   
dear it is ....and this is right... Select * from login where userid = '"+TextBox1.Text+"'and password = '"+TextBox2.Text +"'",con
web works at 11-Aug-11 13:13pm
   
i don't see * in your select statement
 
string myQuery = string.Format("select from login where userid = '{0}' and password = '{1}'", TextBox1.Text, TextBox2.Text);
 
code
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 8

hey friends this code is right ...this code works..thanks
 

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
 
public partial class sigin_in : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
   
    }
    SqlConnection con = new SqlConnection("Data Source=KRISHN-PC;Initial Catalog=sign;Persist Security Info=True;User ID=sa;Password=12345");
    protected void Button1_Click(object sender, EventArgs e)
    {
        //con.Open();
        SqlDataAdapter obj = new SqlDataAdapter("Select * from login where userid = '"+TextBox1.Text+"'and password = '"+TextBox2.Text +"'",con);
        DataSet a = new DataSet();
        obj.Fill(a);
        //con.Close();
        //obj.Update(a);
        if (a.Tables[0].Rows.Count > 0)
        {
            Response.Redirect("home.aspx");
        }
        else
        {
            Label.Text = " wrong pswd";
        }
    }
 
}
  Permalink  
v2

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

  Print Answers RSS
0 Maciej Los 469
1 OriginalGriff 379
2 CPallini 205
3 Sergey Alexandrovich Kryukov 170
4 Sharmanuj 109
0 OriginalGriff 5,649
1 Sergey Alexandrovich Kryukov 4,783
2 Peter Leow 2,954
3 Maciej Los 2,689
4 DamithSL 2,465


Advertise | Privacy | Mobile
Web02 | 2.8.140718.1 | Last Updated 16 Aug 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid