0
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".

4

1 回答 1

1

我已经编写了上面的查询来获取一个字符字段,它以“Specified Cast Not Valid”失败

如果您从数据库中获取数据,则CHAR映射到stringC# 中。所以试试:

AdjustmentType = dgdproduct.Field<string>("AdjustmentType"),

代替

AdjustmentType = dgdproduct.Field<char>("AdjustmentType").ToString(),

您可以修改 的类型AdjustmentType,或者尝试从字符串中获取第一个字符以分配给您的char类型AdjustmentType,例如:

AdjustmentType = dgdproduct.Field<string>("AdjustmentType")[0]

(但以上仅假设返回的字符串中至少有一个字符)

于 2013-04-15T11:44:07.353 回答