Hi,
I will change it slightly.
CREATE proc [dbo].[sp_user]
(
@userid int,
@username varchar(20)
)
as
begin
IF exists(select * from tbl_ins where username=@username)
BEGIN
RAISERROR (16,-1,-1, 'Username Already exits');
Return 1
END
Else
insert into tbl_ins(userid, username) values(@userid,@username)
return -1
end
Now in Code behind:
try {
con.Open();
cmd = new SqlCommand("sp_user", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@userid", txt_uid.Text);
cmd.Parameters.AddWithValue("@username", txt_uname.Text);
cmd.ExecuteNonQuery();
con.Close();
}
catch(Exception ex)
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "alert('"+ex.Message+"');", true);
}
finally
{
if(con!=null)
{
con.Close();
}
}