0

I'm using sqlite as a database. One of the value is null in my database. It's datatype is bytes. Following is the code that I use to retrieve the value,

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

Unfortunately it throws "Invalid cast exception" as the data is empty. How do I return null if the data is empty in the database?

user1241241
  • 664
  • 5
  • 20

1 Answers1

1

You can use IsDBNull:

byte[] blobValue = null;
if(!iData.IsDBNull(4))
{
    blobValue = new byte[iData.GetBytes(4,0,null,0,int.MaxValue)-1];
}
Tim Schmelter
  • 450,073
  • 74
  • 686
  • 939