Click here to Skip to main content
15,891,657 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
using System;
using System..Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
namespace logindemo
{
    public partial class login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void TextBox1_TextChanged(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            string connetionString = "Data Source=INFND-DTP-0493;Initial Catalog=Test_DB;User ID=alok;Password=abcd@1234";
            SqlConnection conn = new 
            SqlConnection(connetionString);
            conn.Open();
            string commText = "Select * from login where User_name='" + TextBox1.Text.Trim() + "' and Password='" + TextBox2.Text.Trim() + "'";
            SqlCommand cmd =new
            SqlCommand(commText, conn);
            SqlDataReader dr = cmd.ExecuteReader();
       
            if (!dr.Read())
            {
                Response.Write("Invalid User");
            }
            else
            {
                conn.Close();
                Session["Username"] = TextBox1.Text;
                Response.Redirect("WebForm1.aspx");  

            }
            /*else
            {
                conn.Close();
                Response.Redirect("~/welcometo.aspx");
            }*/

        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            TextBox1.Text = String.Empty;
            TextBox2.Text = String.Empty;
        }

        protected void Button3_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/Register.aspx");
        }
    }
}
Posted
Updated 23-Mar-15 19:27pm
v2
Comments
King Fisher 24-Mar-15 1:25am    
Do not Repost a question.

1 solution

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