I gave a byte[] stored in database,
I get the byte array in my DataTable from sql
this is my DataTable, System.byte[] is my image in bytes which is stored in my datatbase
now I want to convert this DataTable into list
this is my current Code
var answerList = (from rw in dt.AsEnumerable()
select new RegistrationAnswers()
{
responseID = rw["responseID"].ToString() == string.Empty ? 0 : Convert.ToInt32(rw["responseID"].ToString()),
responseRegID = rw["responseRegID"].ToString() == string.Empty ? 0 : Convert.ToInt32(rw["responseRegID"].ToString()),
responseAnswer = rw["responseAnswer"].ToString(),
_ResponseDocument = rw["responseDocument"], //here i want to validate if rw["responseDocument"] is null or not and if this is not null then assign the byte[] data to _ResponseDocument
formID=Convert.ToInt32(rw["formID"])
}).ToList();
when I updated my code to
//At top
byte[] tempByteArray = new byte[0];
_responseDocument = Convert.IsDBNull((byte[])rw["responseDocument"]) == false ? tempByteArray : (byte[])rw["responseDocument"],
I am getting following error
'Unable to cast object of type 'System.DBNull' to type 'System.Byte[]'.'
i want to validate if rw["responseDocument"] is null or not and if this is not null then assign the byte[] data to _ResponseDocument
