Code:
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.Web.Security;
using System.Data;
public partial class Login : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection Cn = new SqlConnection("server=nikhil;database=mydb;uid=sa;pwd=123");
SqlCommand Cmd = new SqlCommand();
Cmd.Connection = Cn;
Cmd.CommandText = "validateuser";
Cn.Open();
Cmd.CommandType =CommandType.StoredProcedure;
Cmd.Parameters.Clear();
Cmd.Parameters.AddWithValue("", TextBox1.Text);
Cmd.Parameters.AddWithValue("", TextBox2.Text);
SqlDataReader Dr = Cmd.ExecuteReader();
if (Dr.Read())
FormsAuthentication.RedirectFromLoginPage(TextBox1.Text, false);
else
Label1.Text = "user id/password is wrong";
Dr.Close();
Cn.Close();
}
}