【问题标题】:How do I read a null value in the IDataReader?如何在 IDataReader 中读取空值?
【发布时间】:2021-12-12 17:57:19
【问题描述】:

我使用 sqlite 作为数据库。在我的数据库中,其中一个值为 null。它的数据类型是字节。以下是我用来检索值的代码,

        byte[] blobValue = new byte[iData.GetBytes(4,0,null,0,int.MaxValue)-1];

不幸的是,由于数据为空,它会引发“无效的强制转换异常”。如果数据库中的数据为空,如何返回null?

【问题讨论】:

    标签: c# sqlite unity3d idatareader


    【解决方案1】:

    你可以使用IsDBNull:

    byte[] blobValue = null;
    if(!iData.IsDBNull(4))
    {
        blobValue = new byte[iData.GetBytes(4,0,null,0,int.MaxValue)-1];
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多