1

I am using a ADO.NET Entity Data Model for accessing my tables and stored procedure. I mapped stored procedure to my Room table as it returning sfloor column. In Entity Framework, my get request method for floor is:

public List<Floor> GetFloorList(long instID,long userID,string userRole, long buildID, long deptID)
{
    try
    {
        var floors = dbdata.Database.SqlQuery<Room>("GetUserFloorList @nInstID, @nUserID, @sUserRole, @nBuildID, @nDeptID", instID, userID, userRole, buildID, deptID);

        List<Floor> floorList = new List<Floor>();

       foreach (var fl in floors)
        {
            Floor floor = new Floor();
            floor.floorName = fl.sFloor;
            floorList.Add(floor);
        }

        return floorList;
    }
    catch(Exception)
    {
        throw;
    }
}

As I want to list out all the floor name which belongs to corresponding parameters. But when I am running this method it giving me above error.

As per some solution I need to mention data types of each variable but I am not sure how to do that. Can anyone tell me what to do?

Thanks in advance.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • Did you [try google](https://www.google.nl/search?source=hp&ei=3bK4WoSoHcTNwAKb0ZyoCw&q=must+declare+the+scalar+variable+site%3Astackoverflow.com&oq=must+declare+the+scalar+variable+site%3Astackoverflow.com&gs_l=psy-ab.3...1259.9588.0.9829.0.0.0.0.0.0.0.0..0.0....0...1c.1.64.psy-ab..0.0.0....0.m-pEoAayL2I)? – VDWWD Mar 26 '18 at 08:45
  • yes I seached for the same. –  Mar 26 '18 at 09:31

1 Answers1

1

Instead of passing parameters with your variable directly, you have to use new SqlParameter("@nInstID", instID) and do this for all your parameters.