How to save valid and invalid email id using Stored Procedure.

Jayakumars
Posted by Jayakumars under ASP.NET AJAX category on | Points: 40 | Views : 1447
Hi
I have post the sample for save valid and invalid email id using Stored Procedure.

DbConnection


SqlConnection sqlcon = new SqlConnection(ConfigurationManager.ConnectionStrings["DbConnect"].ConnectionString);


Client Side Code

<asp:UpdatePanel ID="UpdatePanel1" runat="server" >
<ContentTemplate>
<table>
<tr>
<td>
Name</td>
<td>
<asp:TextBox ID="TxtName" runat="server"></asp:TextBox>
</td>
<td>
&nbsp;</td>
</tr>
<tr>
<td>
EmailId</td>
<td>
<asp:TextBox ID="TxtEmailId" runat="server"></asp:TextBox>
</td>
<td>
<asp:Button ID="BtEmailId" runat="server" onclick="BtEmailId_Click"
Text="Check" />
</td>
</tr>
</table>

</ContentTemplate>
</asp:UpdatePanel>


Server Side c#

protected void BtEmailId_Click(object sender, EventArgs e)
{
DataTable dt = new DataTable();
sqlcon.Open();
dt = FetData();
SqlCommand cmd = new SqlCommand();
if (Convert.ToInt32(dt.DefaultView[0][0])== 0)
{
cmd = new SqlCommand("sp_validEmailIdInsert", sqlcon);
cmd.Parameters.Add(new SqlParameter("@Name", TxtName.Text));
cmd.Parameters.Add(new SqlParameter("@Emaild", TxtEmailId.Text));
cmd.CommandType = CommandType.StoredProcedure;
cmd.ExecuteNonQuery();
ScriptManager.RegisterStartupScript(this, GetType(), "alert", "alert('Save Sucessfully.');", true);
}
else { ScriptManager.RegisterStartupScript(this, GetType(), "alert", "alert('Invalid Email Id.');", true); }
}



public DataTable FetData()
{

DataTable dtt = new DataTable();
SqlCommand cmd = new SqlCommand();
SqlDataAdapter da = new SqlDataAdapter();
DataTable dt = new DataTable();
try
{
cmd = new SqlCommand("sp_validEmailId", sqlcon);
cmd.Parameters.Add(new SqlParameter("@Emaild", TxtEmailId.Text));
cmd.CommandType = CommandType.StoredProcedure;
da.SelectCommand = cmd;
da.Fill(dt);
}
catch (Exception x)
{
ScriptManager.RegisterStartupScript(this, GetType(), "alert", "alert('Invalid Email Id.');", true);
}
return dt;
}


Sql Server Procedure - for Select Record

Create Proc sp_validEmailId
@Emaild varchar(50)
as
Select COUNT(*) from dbo.Tbl_EmailId where EmailID=@Emaild


Sql Server Procedure - for Insert Record

Create Proc sp_validEmailIdInsert
@Name varchar(50),
@Emaild varchar(50)
as
Insert into Tbl_EmailId(name,emailID) values(@Name,@Emaild)

Comments or Responses

Posted by: T.Saravanan on: 9/22/2012 Level:Silver | Status: [Member] [MVP] | Points: 10
Hi Jayakumar,

I think you have verified, Is the email-id already exist in server and not verified the email-id is valid or not ?

Login to post response