You can achieve this using output parameter in Stored procedures...
Example below..
create proc AddCustomer
@name varchar(50),
@address varchar(50),
@phone varchar(50),
@date datetime,
@output varchar(50) output // output variable
as
begin
if (exists(select cphone from Customer where cphone=@phone))
begin
set @output='This Data exist'
End
else
begin
insert into Customer (cname,cadress,cphone,cdate)
values (@name,@address,@phone,@date)
end
end
c# code below..
SqlParameter message = new SqlParameter("@output",SqlDbType.VarChar,50);
message.Direction = ParameterDirection.Output;
cmd.Parameters.Add(message);
cmd.ExecuteNonQuery();
ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "tmp", "<script type='text/javascript'>alert('" +message.value.ToString() +"');</script>", false);
Hope it helps..