var dadproductlist = from dgdproduct in dadData.Tables[0].AsEnumerable()
select new DeliveryAdjustmentProduct
{
AdjustmentQuantity = dgdproduct.Field<int>("AdjustedQty"),
AdjustmentType = dgdproduct.Field<char>("AdjustmentType").ToString(),
DeliveredDate = dgdproduct.Field<DateTime>("ExpectedDate"),
ProductCode = dgdproduct.Field<int>("ProductNum").ToString(),
RevisedQuantity = dgdproduct.Field<int>("RevisedOrderQty"),
SupplierId = dgdproduct.Field<int>("SupplierId").ToString(),
TrailerId = "Pradeep"
};
我已经编写了上面的查询以获取字符字段,但"Specified Cast Not Valid"
失败了。
答案 0 :(得分:1)
我已经编写了上面的查询来获取charecter字段,它失败了 “指定的演员无效”
如果从数据库获取数据,则CHAR
将映射到C#中的string
。所以试试:
AdjustmentType = dgdproduct.Field<string>("AdjustmentType"),
而不是
AdjustmentType = dgdproduct.Field<char>("AdjustmentType").ToString(),
您可以修改AdjustmentType
的类型,或者尝试将字符串中的第一个字符分配给char
类型AdjustmentType
,如:
AdjustmentType = dgdproduct.Field<string>("AdjustmentType")[0]
(但上面只假设返回的字符串中至少有一个字符)