我使用 sqlite 作為資料庫。我的資料庫中的值之一為空。它的資料型別是位元組。以下是我用來檢索值的代碼,
byte[] blobValue = new byte[iData.GetBytes(4,0,null,0,int.MaxValue)-1];
不幸的是,由于資料為空,它會拋出“無效的強制轉換例外”。如果資料庫中的資料為空,如何回傳null?
uj5u.com熱心網友回復:
您可以使用IsDBNull:
byte[] blobValue = null;
if(!iData.IsDBNull(4))
{
blobValue = new byte[iData.GetBytes(4,0,null,0,int.MaxValue)-1];
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/339685.html
上一篇:一個變數的不同型別
