我有一个班级客户。我正在尝试从 access db 数据库加载数据。
客户类结构如下:
public class Customer
{
public int CustomerId { get; set; }
public string CustomerName { get; set; }
public string CustAddress { get; set; }
public string PnoneNo { get; set; }
public string MobileNo { get; set; }
public string CstNo { get; set; }
public string DlNo { get; set; }
public decimal BalAmt { get; set; }
}
我在db中的表结构如下:
现在,当我尝试在客户类中加载数据时,它会引发错误:
“指定的演员表无效。”
为了将数据加载到类中,我使用以下代码:
public static List<Customer> LoadListItems(string strTable, string strOrderBy)
{
List<Customer> lstCustomer=null;
try
{
DataUtility objDataUtility = new DataUtility();
DataTable objCustomerList = objDataUtility.LoadCustomerInfo(strTable, strOrderBy);
lstCustomer= objCustomerList.AsEnumerable().Select(row =>
new Customer
{
CustomerId = row.Field<int>("CID"), //throwing error for this line
CustomerName = row.Field<string>("salPNm"),
CustAddress = row.Field<string>("cadd"),
MobileNo = row.Field<string>("cmbl"),
PnoneNo = row.Field<string>("cph"),
DlNo = row.Field<string>("cDlN"),
CstNo = row.Field<string>("cTin"),
BalAmt = row.Field<decimal>("cobal")
}).ToList();
}
catch (Exception ex)
{
throw ex;
}
return lstCustomer;
}
在上面的方法CustomerId = row.Field<int>("CID"),
中,当我评论这一行时,它会引发错误,因为它工作正常。请帮助我如何从 iennumrable 列表中获取 int 值。
提前致谢。埃什维尔