我正在逐行读取excel文件,并将项目添加到将保存到数据库的集合 。测试空值和数字的日期值
在数据库:
NumberValue1 to NumberValue3 are numbers and nullable.
Datevalue1 to Datavalue5 are dates and nullable.
BooleanYN1 is a varchar2(1 char) and nullable.
我希望能够以测试这些数字,字符串和datevalues使我不是在数据库中插入空。
我该如何处理?对于低于测试的字符串应该没问题。 我特别关注日期变量和数字。
if ((col2Value != null && col3Value != null & col4Value != null))
{
excelFileDataList.Add(new ExcelData
{
BusinessUnitCode = col2Value.ToString(),
GenericJobId = Convert.ToInt32(col3Value),
NumberValue1 = Convert.ToInt32(col8Value) == null ? 0 : Convert.ToInt32(col8Value),
NumberValue2 = Convert.ToInt32(col8Value) == null ? 0 : Convert.ToInt32(col9Value),
NumberValue3 = Convert.ToInt32(col8Value) == null ? 0 : Convert.ToInt32(col10Value),
StringValue1 = col18Value == null ? "" : col18Value.ToString(),
StringValue2 = col19Value == null ? "" : col19Value.ToString(),
StringValue3 = col20Value == null ? "" : col20Value.ToString(),
DateValue1 = Convert.ToDateTime(col28Value) == null ? : Convert.ToDateTime(col28Value),
DateValue2 = Convert.ToDateTime(col29Value) == null ? : Convert.ToDateTime(col29Value),
DateValue3 = Convert.ToDateTime(col30Value) == null ? : Convert.ToDateTime(col30Value),
DateValue4 = Convert.ToDateTime(col31Value) == null ? : Convert.ToDateTime(col31Value),
DateValue5 = Convert.ToDateTime(col32Value) == null ? : Convert.ToDateTime(col32Value),
BooleanYN1 = col34Value == null ? "" : col34Value.ToString(),
BooleanYN2 = col35Value == null ? "" : col35Value.ToString(),
BooleanYN3 = col36Value == null ? "" : col36Value.ToString(),
});
我一直在获取对象引用未设置为对象的实例。我认为这是空值的结果。有Excel电子表格的各种列这是可以接受空值
非常感谢。这非常有帮助。 – user2320476