You don't need to call db.SubmitChanges(); It's required with modified LINQ to SQL objects only.
How can I use a stored procedure in Linq-to-SQL and asp.net?
-
16-07-2023 - |
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;
}
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow