How Entity get NoCount result when call Store procedure

Last Reply one day ago By AnandM

Posted 4 days ago

The SQL server store procedure:

 

CREATE PROCEDURE pUsersCRUD
	@Action varchar(10),
	@UserID int = null,	
	@UserName nvarchar(20) = null,
	@Password nvarchar(200) = null,
	@Email nvarchar(30) = null,
	@Permision smallint = 0,	
	@LastLoginDate datetime = null
AS
BEGIN
	SET NOCOUNT ON;
	--SELECT
	IF @Action = 'SELECT'
		BEGIN
			SELECT *FROM Users 
		END
	..........................................
	--INSERT
	IF @Action = 'INSERT'
		BEGIN
			IF EXISTS(SELECT UserId FROM Users WHERE Username = @Username)
				BEGIN
					SELECT -1 -- Username exists.
				END
			ELSE IF EXISTS(SELECT UserId FROM Users WHERE Email = @Email)
				BEGIN
					SELECT -2 -- Email exists.
				END
			ELSE
	.........................................

Entity in Controller :

public JsonResult AddUserJson(User u)
        {
            //TestEquipDBEntities.Users.Add(u);
            string strResult = TestEquipDBEntities.DoUsersCRUD("INSERT", null, u.UserName, u.Password, u.Email, u.Permision, null).ToString();

            return Json(1, JsonRequestBehavior.AllowGet);
        }

 How the Entity receive the result: -1 or -2 when the data exist when do insert sql

You are viewing reply posted by: AnandM 4 days ago.
I agree, here is the link: http://e-iceblue.com/free-api