Validating Duplicate Email Id from Database while Form Filling

Self-innovator
Posted by Self-innovator under ASP.NET category on | Points: 40 | Views : 5097
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);
}
}

Comments or Responses

Posted by: T.saravanan on: 12/26/2011 Level:Silver | Status: [Member] [MVP] | Points: 10
Kindly post your code insdie the code tag and give little bit explantion about your code.

Login to post response