Strongly Typed Dataset with Image Data

  • Thread starter Thread starter heath
  • Start date Start date
H

heath

I am converting an application to an n-tier application in asp.net
2005. All tiers are in vb. I have created a strongly typed dataset
from a stored proc that takes an ID and returns an ID and associated
image (a fairly large pdf) from a mssql 2005 db. Whenever I try to
access the column with the image data, I get the following error:
Unable to cast object of type 'System.DBNull' to type
'System.Byte[]'. It points the auto-generated code in the
MasterData.Designer.vb; specifically the Return statement in the
Property Get:

<Global.System.Diagnostics.DebuggerNonUserCodeAttribute()> _
Public Property file_data() As Byte()
Get
Return
CType(Me(Me.tableFaxDocument.file_dataColumn),Byte())
End Get
Set
Me(Me.tableFaxDocument.file_dataColumn) = value
End Set
End Property

Now, I know for a fact that this stored proc is definitely NOT
returning a NULL. It does return exactly what it should. The old
code which works fine is:

Dim MySqlConnection As New SqlConnection(ConnStr)
Dim MySqlCommand As SqlCommand
Dim MySqlReader As SqlDataReader
Try
MySqlConnection.Open()
MySqlCommand = New SqlCommand("sel_faxes",
MySqlConnection)
MySqlCommand.CommandType = CommandType.StoredProcedure
MySqlCommand.Parameters.AddWithValue("@fax_id",
Session("fax_id"))
MySqlReader = MySqlCommand.ExecuteReader()
MySqlReader.Read()
Dim fileData() As Byte =
CType(MySqlReader("file_data"), Byte())
MySqlReader.Close()
pdfFax.Visible = True
pdfFax.PdfOpen.Zoom = "75"
pdfFax.LoadPdf(filedata)

Compare this to the autocode that returns the image and it's basically
the same thing. I have searched for hours for a solution and haven't
even found similar problems. Does anyone have a solution? I'm
guessing that somewhere in the auto-generated MasterData.Designer.vb,
the image data isn't being loaded correctly and is being interpreted
as NULL but I can't for the life of me figure out where or why. Any
suggestions would be much appreciated. Thanks.
 
Heath,

In my idea is the generated code not correct, it needs as you wrote a stream
to generate a blob to a byte array.

You can try connect.microsoft.com to report that, but that will not help
you.

If you need a workaround, then have a look at this code.

http://www.vb-tips.com/DataSetImage.aspx

Cor
 
Back
Top