Store Procedure
Create proc [dbo].[sp_InsPersonInfo]
@pName varchar(50),
@pEmail varchar(80)
as
declare @Count as int
set @Count=(select count(id) from Persons where PersonEmail=@pEmail)
select @Count as DuplicateEmail
if @Count=0
begin
insert into Persons values(@pName,@pEmail)
end
Create a Function in Data Layer in .cs
public DataSet Insert(string pName,string pEmail)
{
cnn = new SqlConnection(Conn);
cmd = new SqlCommand("sp_InsPersonInfo", cnn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@pName", pName);
cmd.Parameters.AddWithValue("@pEmail", pEmail);
ada = new SqlDataAdapter(cmd);
ds = new DataSet();
ada.Fill(ds);
return ds;
}
Submit_Click()
{
DAL = new PersonDATAlayer();
ds = new DataSet();
ds=BAL.Insert(txtName.Text,txtEmail.text)
int Count;
Count = Convert.ToInt32(ds.Tables[0].Rows[0]["DuplicateEmail"].ToString());
if (Count > 0)
{
string strjscript = "<script language='javascript'>alert('Email id already exists ');</script>";
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "myscript", strjscript);
}
}