By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,044 Members | 1,287 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,044 IT Pros & Developers. It's quick & easy.

get image data from dataset (insead of directly from db)

P: n/a
I have a slightly different twist on the old question "How do I display
images stored in my database?".

My application does not talk directly to the database. It uses a COM+ dll to
deliver serialized datasets. Then I de-serialize those datasets and work
from those.

All the examples I've seen use a SQL adaptor to stream the data and I can't
quite make that work directly from a dataset. I've tried the following code
but I get a "Specified cast is invalid" when I try to assign a byte array
variable the value from the dataset field (which I see in the debugger is of
a type 'bin.hex'). I also can't seem to get convert.tobyte to work (probably
since it's a byte array). Anyone got any hints for me? Seems like I'm
close, but no cigar.

Dim oRow As DataRow

oRow = oDs.Tables(1).Rows(0)

Dim MyData() As Byte

MyData = oRow.Item("mug_shot") 'this is where I hit the casting error

Response.Buffer = True

Response.ContentType = "Image/JPEG"

Response.BinaryWrite(MyData)
If it matters, these are jpeg images stored as type images in sql server,
but are delivered as strings (serialized datasets). Thanks!

Matt
Nov 18 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hi Matt,

Shouldn't that be:

Dim MyData As Byte()

Ken

"MattB" <so********@yahoo.com> wrote in message
news:c7************@ID-86156.news.uni-berlin.de...
I have a slightly different twist on the old question "How do I display
images stored in my database?".

My application does not talk directly to the database. It uses a COM+ dll
to
deliver serialized datasets. Then I de-serialize those datasets and work
from those.

All the examples I've seen use a SQL adaptor to stream the data and I
can't
quite make that work directly from a dataset. I've tried the following
code
but I get a "Specified cast is invalid" when I try to assign a byte array
variable the value from the dataset field (which I see in the debugger is
of
a type 'bin.hex'). I also can't seem to get convert.tobyte to work
(probably
since it's a byte array). Anyone got any hints for me? Seems like I'm
close, but no cigar.

Dim oRow As DataRow

oRow = oDs.Tables(1).Rows(0)

Dim MyData() As Byte

MyData = oRow.Item("mug_shot") 'this is where I hit the casting error

Response.Buffer = True

Response.ContentType = "Image/JPEG"

Response.BinaryWrite(MyData)
If it matters, these are jpeg images stored as type images in sql server,
but are delivered as strings (serialized datasets). Thanks!

Matt


Nov 18 '05 #2

P: n/a
Thanks, I think you are correct, but I still have the problem of the data
being in 'bin.hex'.
Any suggestions or examples for converting the image data from 'bin.hex' to
a bit array?

Matt

Ken Cox [Microsoft MVP] wrote:
Hi Matt,

Shouldn't that be:

Dim MyData As Byte()

Ken

"MattB" <so********@yahoo.com> wrote in message
news:c7************@ID-86156.news.uni-berlin.de...
I have a slightly different twist on the old question "How do I
display images stored in my database?".

My application does not talk directly to the database. It uses a
COM+ dll to
deliver serialized datasets. Then I de-serialize those datasets and
work from those.

All the examples I've seen use a SQL adaptor to stream the data and I
can't
quite make that work directly from a dataset. I've tried the
following code
but I get a "Specified cast is invalid" when I try to assign a byte
array variable the value from the dataset field (which I see in the
debugger is of
a type 'bin.hex'). I also can't seem to get convert.tobyte to work
(probably
since it's a byte array). Anyone got any hints for me? Seems like
I'm close, but no cigar.

Dim oRow As DataRow

oRow = oDs.Tables(1).Rows(0)

Dim MyData() As Byte

MyData = oRow.Item("mug_shot") 'this is where I hit the casting error

Response.Buffer = True

Response.ContentType = "Image/JPEG"

Response.BinaryWrite(MyData)
If it matters, these are jpeg images stored as type images in sql
server, but are delivered as strings (serialized datasets). Thanks!

Matt


Nov 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.