For Login Check
Before we learnt how to make Login Check Store procedure but This article explain How to implement it and make Webform for Login check
#Open Visual Studio and make new project then Add new webform
Now design the webform
public partial class WebForm2 : System.Web.UI.Page
{
SqlConnection con = new SqlConnection();
|
protected void Page_Load(object sender,
EventArgs e)
{
con.ConnectionString = ConfigurationManager.ConnectionStrings["cn"].ConnectionString;
if (con.State==ConnectionState.Closed)
{
con.Open();
}
}
|
# Method to Checkuser (for Reusability)
private Int32 CheckUser(String u, String p)
{
SqlCommand cmd = new SqlCommand("LoginCheck", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@un", SqlDbType.VarChar, 50).Value = u;
cmd.Parameters.Add("@up", SqlDbType.VarChar, 50).Value = p;
cmd.Parameters.Add("@ret", SqlDbType.Int);
cmd.Parameters["@ret"].Direction =
ParameterDirection.ReturnValue;
cmd.ExecuteNonQuery();
Int32 k = Convert.ToInt32(cmd.Parameters["@ret"].Value);
cmd.Dispose();
return k;
}
|
SqlCommand cmd = new SqlCommand("LoginCheck", con); - 4 of 5
cmd.Parameters.Add("@ret", SqlDbType.Int); - To return value.
Return value have only 1 parameter.
# Login button query
Add label on design webform
protected void Button1_Click(object sender,
EventArgs e)
{
Int32 d = CheckUser(TextBox1.Text, TextBox2.Text);
if (d==-1)
{
Label1.Text = "WrongUser";
}
if (d==-2)
{
Label1.Text = "WrongPassword";
}
if (d==1)
{
Label1.Text = "Login";
}
}
|
# Add data in table tbuser(make one)
Open dataconnection>table> show table on
tbuser
Add data in it.
Run the program
No comments:
Post a Comment