I suspect the issue is that SaveToStream
is leaving you at the end
of the stream; unfortunately, stream.Read(bytes, 0, stream.Length)
will still work; it will just read 0 bytes into your array. You can verify this by checking the return value from stream.Read
, which is the total number of bytes read.
So, if you set the stream.Position
to 0 before attempting to read it:
Try
Dim stream As New System.IO.MemoryStream()
customFormatWorkBook.SaveToStream(stream, SpreadsheetGear.FileFormat.Excel8)
stream.Position = 0;
Dim bytes(stream.Length - 1) As Byte
stream.Read(bytes, 0, stream.Length)
docDataSet.Tables(0).Rows(0)("FORMATTED_DOC") = bytes
stream.Close()
Catch ex As Exception
End Try
docDataAdapter.Update(docDataSet, "DOCUMENTS")
Then that should work.