Question

I have stored procedure that forbid from duplicate email address .

create PROCEDURE [dbo].[CheckEmail1]
(@email nvarchar(50))
AS
BEGIN            
   DECLARE @ERORR NVARCHAR(50)
   SET NOCOUNT ON;

   if not exists (SELECT C.Email FROM Customer C WHERE Email=@email)
   BEGIN
      INSERT INTO Customer (Email) VALUES (@email) 
   END
   ELSE
   BEGIN
      declare @errormessage nvarchar(50) = 'This Email Address is Exists'
      RAISERROR (@errormessage,11,1)
   END
END

I want to use this stored procedure in asp.net textbox ? How can I do that? and this is my C# Code :

try
{
   var db = new DataClassesDataContext();
   db.CheckEmail1(TextBox1.Text);
   db.SubmitChanges();
}
catch (Exception ex)
{
   Label6.Text = ex.Message;
}
Was it helpful?

Solution

You don't need to call db.SubmitChanges(); It's required with modified LINQ to SQL objects only.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top