我有问题。这是我的代码使用 LINQ。
var resultCases = from row2 in dtCases.AsEnumerable()
where row2.Field<int>("caseID") == caseID2
select new
{
caseName = row2["caseName"].ToString(),
caseCourtPlace = row2["caseCourtPlace"].ToString(),
caseCourtRef = row2["caseCourtRef"].ToString(),
caseOfficeRef = row2["caseOfficeRef"].ToString(),
effectiveDate = ((DateTime)row2["caseEffectiveDate"]),
closedDate = ((DateTime)row2["caseClosedDate"]),
caseFolderPath = row2["casesFolderPath"].ToString(),
category = row2["categoryName"].ToString(),
department = row2["departmentName"].ToString(),
empName = row2["empName"].ToString(),
judgeName = row2["judgeName"].ToString(),
asName = row2["asCasesName"].ToString(),
};
如果closedDate
或effectiveDate
返回DBnull.Value
,我得到
未处理 InvalidCastException - 指定的强制转换无效。
那么如何防止这个错误呢?