if ((booking.BookingsVoucher[i].RedemptionReloc != null)).
Run Code Online (Sandbox Code Playgroud)
我在这里得到例外.RedemptionReloc在dbase中具有null值
Redemption TimeSttmp
NULL
Redemption Reloc
NULL
RedeemedCurrencyC
NULL
Redeemed Amo_
NULL
Run Code Online (Sandbox Code Playgroud)
尝试使用DBNULL.value.equal(booking.BookingsVoucher [i] .RedemptionReloc).但这也引起了异议.这是异常日志
添加凭证详细信息时出现异常:System.Data.StrongTypingException:表'BookingsVoucher'中列'RedemptionReloc'的值为DBNull.---> System.InvalidCastException:无法将类型为'System.DBNull'的对象强制转换为'System.String'.
小智 6
将NullValue项更改为Null或Empty,并进行相应的检查.
DataSet1 ds1 = new DataSet1();
SqlConnection cn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["ContosoUniversity2ConnectionString"].ConnectionString);
using (cn)
{
using (SqlDataAdapter adapter = new SqlDataAdapter("SELECT * FROM Department", cn))
{
adapter.Fill(ds1.Department);
foreach (DataSet1.DepartmentRow row in ds1.Department.Rows)
{
if (row.Name != null)
{
Console.WriteLine(row.Name);
}
}
}
}
Run Code Online (Sandbox Code Playgroud)