简体   繁体   English

C#中的“无效的列名”

[英]“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.即使所有列都存在于 Sql Server 的表中,我在 Visual Studio 中收到错误“无效的列名”。 Table column Name is AttandanceId but it shows error of “Invalid Column Name” ie.表列名称是 AttandanceId 但它显示“无效的列名称”错误,即。 AttandanceId1 which is not present there in Sql Server Table Under Attandance AttandanceId1 在 Attandance 下的 Sql Server 表中不存在

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.我认为您对 sql 表进行了一些更改,然后尝试更新未成功更新的数据模型,例如,正如您提到的 AttandanceId 和 AttandanceId1 显示冲突。

simply do简单地做

  • 1: delete your table or complete model and clean your solution. 1:删除您的表或完整模型并清理您的解决方案。

  • 2: add table/model again and build your solution, every think will be 2:再次添加表/模型并构建您的解决方案,每个想法都会
    fine美好的

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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