2016-07-08 237 views
1
if ((booking.BookingsVoucher[i].RedemptionReloc != null)). 

我在這裏得到異常。 RedemptionReloc具有以dBASE空值拋出'System.Data.StrongTypingException'類型的異常C#

Redemption TimeSttmp 
NULL 
Redemption Reloc 
NULL 
RedeemedCurrencyC 
NULL 
Redeemed Amo_ 
NULL 

使用DBNULL.value.equal(booking.BookingsVoucher [I] .RedemptionReloc)嘗試。但這也引起了極大的關注。 這裏是例外,登錄加入憑證詳細

例外:System.Data.StrongTypingException:在表中的值列'RedemptionReloc「BookingsVoucher」是爲DBNull。 ---> System.InvalidCastException:無法將類型爲「System.DBNull」的對象轉換爲鍵入「System.String」。

+0

我們需要更多信息。 'BookingsVoucher'是某種類型的集合。這是什麼類型,它是如何定義的? 你用什麼從數據庫中獲取數據到這種類型?帶有數據表的ADO.NET?實體框架?定製解決方案? – seangwright

回答

3

enter image description here

更改NullValue屬性項爲零或爲空和你做相應的檢查。

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); 
        } 

       } 
      } 
     } 
+0

似乎像實體框架中的錯誤 – makdu

+0

您使用哪種數據訪問技術強類型數據集或EF? –

相關問題