Check Availability Of UserName

 
protected void LinkButton1_Click(object sender, EventArgs e)
{
if (TextBox1.Text != "")
{
reg.checkusername1 = TextBox1.Text;
int x = reg.checkavailability();
if (x == 1)
{
// ScriptManager.RegisterStartupScript(this, this.GetType(), "dg", "", false);
}
else
{
// ScriptManager.RegisterStartupScript(this, this.GetType(), "dg", "", false);
}
}
else
{
// ScriptManager.RegisterStartupScript(this, this.GetType(), "dg", "", false);
}
}


///////////////Class File////////////

public int checkavailability()
{
if (conn.State == ConnectionState.Open)
{
conn.Close();
}
conn.Open();
SqlCommand cmd = new SqlCommand("checkavailability", conn);
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter param = new SqlParameter();
param.Direction = ParameterDirection.ReturnValue;
param = cmd.Parameters.Add("@username", SqlDbType.VarChar, 100);
param.Direction = ParameterDirection.Input;
param.Value = checkusername;
param = cmd.Parameters.Add("@flag", SqlDbType.Int);
param.Direction = ParameterDirection.ReturnValue;
cmd.ExecuteNonQuery();
return Convert.ToInt32(cmd.Parameters["@flag"].Value.ToString());
}

/////////Stored Procedure//////////////

ALTER PROCEDURE [dbo].[checkavailability]
@username varchar(100)
AS
BEGIN
declare @flag int
select @flag=count(*) from userregistration where username=@username
if(@flag<>0)
begin

return 1
end
else
begin
return 2
end
END


Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: