I am trying to get the current userid from the parameter and to check if it exists in a Database Table using stored procedure
public PartialViewResult AllStates(string state, string userid)
{
SqlCommand cmd = new SqlCommand();
Following following = new Following();
cmd.Parameters.Add("@userid", SqlDbType.BigInt).Value = userid;
List<Farmer> model = db.Farmer.Where(u => u.FarmState == state).Take(3).ToList();
var modelfollow = db.Following.SqlQuery("[dbo].[SelectFollow]").ToList();
ViewBag.folo = modelfollow;
return PartialView("_UsersList", model );
}
This is my stored Procedure
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE SelectFollow
@userid INT
AS
BEGIN
DECLARE @HasFollowed BIT
IF EXISTS(SELECT * FROM dbo.Followings Where UserId = @userid)
BEGIN
SET @HasFollowed = 1
END
ELSE
BEGIN
SET @HasFollowed = 0
END
END
GO
Is there any thing I'm doing wrong?