Strongly Typed Dataset with Image Data

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.
 
C

Cor Ligthert[MVP]

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top