-1
我在嘗試使用下面的代碼如何解決無法投類型的對象「System.DBNull」輸入「System.String`
無法投類型的對象,以獲取數據」系統。爲DBNull '鍵入' System.String`
private void gridView1_CustomUnboundColumnData(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDataEventArgs e)
{
if (e.IsGetData)
{
DataRow row = ((DataRowView)e.Row).Row as DataRow;
string value = (string)row["BOM - RIM PN"];
var results = from myRow in this.wHLMASTERDETAIL.RIMS.AsEnumerable()
where myRow.Field<string>("STOCK NO") == value
select myRow;
e.Value = results.ToList().Count;
}
雖然這樣做的原因是DBNull類型的特殊情況,這類代碼的用戶必須知道爲什麼這個確切的工作。在幾乎所有情況下,鑄造字符串都不能通過.ToString完成。對於工作答案+1,以及對額外類型檢查的說明。 – welrocken