2016-09-22 26 views
2

我在數據表中有一個整數列,我想在該列中設置空值。我已經完成了AllowDBNull tr​​ue,但如果增加了空值,它仍然不起作用。如何在Integer類型的數據表的列中設置空值

以下是我已經爲

enter image description here

我得到以下異常 enter image description here

誰能幫助MI這個做配置?

+0

請,提供錯誤的文字表示。有些使用無法看到圖像。 – eocron

回答

-2

請將該值聲明爲可空int(int?)。那麼它將接受所有的空值

0

的 「?」在數據類型後面可以爲空。

例子:

int? t = null; 

所以nzrytmn是正確的!

0

你可以試試數據列的NullValue屬性設置爲東西是不是「(ThrowException)

2

您不能分配的DBNull在數據表中的字段。當您允許DataTable中的DBNull時,會生成一個額外的方法。在這種情況下:SetParentApplicationRoleIdNull()

例如:

var newRow = DataSet.ChildApplications.NewChildApplicationRow(); 
newRow.AField = "Some text"; 
newRow.SetParentApplicationRoleIdNull(); 
DataSet.ChildApplications.AddChildApplicationRow(newRow); 

這也同時檢查值。你不能直接使用「財產」 ParentApplicationRoleId,如果你想讀它,你就會有另一個生成的方法首先要檢查它:IsParentApplicationRoleIdNull()

例如:

foreach(var row in DataSet.ChildApplications.Rows) 
{ 
    if(!row.IsParentApplicationRoleIdNull()) 
    { 
     Trace.WriteLine($"ParentApplicationRoleId: {row.ParentApplicationRoleId}"); 
    } 
    else 
    { 
     Trace.WriteLine("ParentApplicationRoleId: is DBNull, and can't be shown"); 
    } 
} 
相關問題