protected void btnregister_Click(object sender, EventArgs e)
{
if (Page.IsValid)
{
string cs = ConfigurationManager.ConnectionStrings["SampleConnectionString"].ConnectionString;
using (SqlConnection con = new SqlConnection(cs))
using(SqlCommand cmd = new SqlCommand("spRegisterUser", con))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Username", txtusername.Text);
cmd.Parameters.AddWithValue("@Password", txtpassword.Text);
cmd.Parameters.AddWithValue("@Email", txtemail.Text);
con.Open();
int count = (int)cmd.ExecuteScalar();
if ( count == -1)
{
Label1.Text = "User id is not avalilable please choose another one";
}
else
{
Response.Redirect("~/Login.aspx");
}
}
and Stored procedure is
CREATE Procedure spRegisterUser
@Username nvarchar(50),
@Password nvarchar(50),
@Email nvarchar(50)
As
Begin
Declare @Count int
Declare @Returncount int
Select @Count = COUNT(Username)
from tblUsers Where Username=@Username
if @Count > 0
Begin
Set @Returncount = -1
End
Else
Begin
set @Returncount = 1
Insert into tblUsers values(@Username,@Password,@Email)
End
Select @Returncount as ReturnValue
End
i don't know iam not getting any exception and the values not getting stored. please help me is there anything wrong with that code