简体   繁体   中英

“Invalid Column Name” in C#

I get an error “Invalid Column Name” in Visual studio even when all the columns are present in the table in Sql Server. Table column Name is AttandanceId but it shows error of “Invalid Column Name” ie. AttandanceId1 which is not present there in Sql Server Table Under Attandance

public IActionResult EmployeeReport(int id)
{
    var viewModel = new AttandanceViewModel();
    var EmployeeList = _dbContext.Employees.ToList();

    viewModel.DropFirstName = new SelectList(EmployeeList, "EmployeeId", "FirstName");
    viewModel.AttList = _dbContext.Attandance.Where(i => i.EmpId == id).ToList();
    ViewBag.Id = id;
    var Count = viewModel.AttList.Count();

    ViewBag.Counts = Count;
    return View(viewModel);
}

i think you made some changes in sql table and then try to update data model, which is not updated successfully eg As you mention AttandanceId and AttandanceId1 which shows conflict.

simply do

  • 1: delete your table or complete model and clean your solution.

  • 2: add table/model again and build your solution, every think will be
    fine

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM