.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> ASP.NET Controls >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Data Retriving from the login page

Posted By:Aarureddy@Anjireddy       Posted Date: December 10, 2010    Points: 15    Category: ASP.NET Controls    URL: http://www.dotnetspark.com  

This is used for validating username and password into database
 

Declaration:-

string connection = ConfigurationManager.AppSettings["Connection"].ToString();
    SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["Connection"].ToString());
    SqlCommand cmd = new SqlCommand();
    DataSet ds = new DataSet();
    SqlDataReader dr;


Button login_Click event:-

string chqsql = "select * from Register where Username='"+txtusername.Text+"' and Password='"+txtpassword.Text+"'";
        SqlConnection con = new SqlConnection(connection);
        DataSet ds = new DataSet();
        SqlDataAdapter da = new SqlDataAdapter();
        con.Open();
        SqlCommand mycommand = new SqlCommand(chqsql,con);
        mycommand.ExecuteNonQuery();
        da.SelectCommand = mycommand;
        da.Fill(ds);
        if (ds.Tables[0].Rows.Count > 0)
        {
            con.Close();
            string name = txtusername.Text;
           Response.Redirect("Entry_Details.aspx?arg=" + name);
        }
        else
        {
            Response.Write("");
        }       
    }

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend