c# - 抛出类型为 'System.Data.StrongTypingException' C# 的异常

标签 c# exception

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'.

最佳答案

enter image description here

将 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/

相关文章:

c# - Microsoft Practice 使用 Unity 寄存器类型

php - 在 __destruct() 中,您如何查看当前是否存在异常?

c# - 传递 IOC 容器的替代方案

java - 为什么下面的程序会出现PatternSyntaxException?

Java:NoClassDefFoundError 使用 Apache Commons CLI 1.2

不调用 Thread.join() 时的 C++ 多线程异常

exception - 为什么说异常对于输入验证来说如此糟糕?

c# - 检测目录中的更改

c# - 无法加载文件或程序集 "System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"

c# - SHA256CryptoServiceProvider 不符合 FIPS 标准?