HI
this my table in database
S_register
Mobile
|
address
|
Name
|
id
|
123456
|
paris
|
sara
|
1
|
236548
|
india
|
Jack
|
2
|
and in register.aspx page I have some TB that users can enter their data on it :
SP
ALTER procedure [dbo].[insertSreg]
@Name nvarchar(40),
@Address nvarchar(Max@Mobile nvarchar(20),@Success NVARCHAR(60) OUTPUT
as
begin
IF NOT EXISTS(SELECT id FROM S_register WHERE Mobile = @Mobile)
begin
insert into S_register (Name,Address
Mobile)
values(@Name,@Address
@Mobile)
end
ELSE
SET @Success = 'please select other name.'
end
Behind code
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
SqlCommand _cmd = new SqlCommand("insertSreg", _cn);
_cmd.CommandType = CommandType.StoredProcedure;
_cn.Open();
_cmd.Parameters.AddWithValue("@Name", txtname.Text);
_cmd.Parameters.AddWithValue("@Address", txtDname.Text);
_cmd.Parameters.AddWithValue("@Mobile", Txtmob.Text);
_cmd.Parameters.Add("@Success", SqlDbType.NVarChar, 60);
_cmd.Parameters["@Success"].Direction = ParameterDirection.Output;
_cmd.ExecuteNonQuery();
Response.Redirect("success.aspx");
_cn.Close();
LBLERROR.Text = _cmd.Parameters["@Success"].Value.ToString();
}
I want when users enter their Name in TB if in above Table was same name it don't insert any data in Table and show error that "Please Select Othername" @success parameter that I define in SP
and if they don't enter duplicate name in TB it insert data in table and go to success.aspx page
but here when users enter duplicate name it don't insert data in table but it don't show error message (@success parameter) and go to success.aspx page?I want if they enter duplicate name it showw error and doesn't go to success.aspx page
What should i do?
Best Regards