Step 1:Use NameSpaces As
using System.Data.SqlClient;
Step 2: Global Declaration Are:
SqlConnection con = new SqlConnection("Ur Connection");
Step 3:Page_Load
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
this.ViewState["count"] = 0;
}
}
Step 4:write a Method
public void m()
{
string user = "";
string pass = "";
string str = "select * from tbl_Login where username='" + TextBox1.Text + "' and password='" + TextBox2.Text + "'";
//string count = "";
con.Open();
SqlCommand cmd = new SqlCommand(str, con);
cmd.CommandType = CommandType.Text;
SqlDataReader dr;
dr = cmd.ExecuteReader();
while (dr.Read() == true)
{
user = dr[1].ToString();
pass = dr[2].ToString();
}
dr.Close();
if (TextBox1.Text == user && TextBox2.Text == pass)
{
Response.Redirect("Default2.aspx");
}
else
{
Label1.Text = "Login Failed";
}
con.Close();
Step 5: On Button Click
protected void Button1_Click(object sender, EventArgs e)
{
int i = Convert.ToInt32 (this.ViewState["count"].ToString())+1;
//int i = this.ViewState["count"] + 1;
this.ViewState["count"]=i;
if (i <=3)
{
m();
}
else
{
Label1.Text = "Please Contact Admin.. YOuR Login Limit Exceed";
}
}
fake
ReplyDeleteit will work i have used wat error r u getting
ReplyDelete