if ((booking.BookingsVoucher[i].RedemptionReloc != null)).
我在这里遇到异常。 RedemptionReloc 在数据库中有空值
Redemption TimeSttmp
NULL
Redemption Reloc
NULL
RedeemedCurrencyC
NULL
Redeemed Amo_
NULL
尝试使用 DBNULL.value.equal(booking.BookingsVoucher[i].RedemptionReloc)。但这也会引发异常。 这是异常日志
Exception in adding Voucher Details: System.Data.StrongTypingException: The value for column 'RedemptionReloc' in table 'BookingsVoucher' is DBNull. ---> System.InvalidCastException: Unable to cast object of type 'System.DBNull' to type 'System.String'.
最佳答案
将 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);
}
}
}
}
关于c# - 抛出类型为 'System.Data.StrongTypingException' C# 的异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38258673/