Storing an image in a dataset

E

EMW

Hi,

Is it possible to store an image in a dataset?

I've tried this:
Dim col As new DataColumn()
Dim cols As DataColumnCollection
Dim tp As Type
dsFoto.Tables.Clear()
dsFoto.Tables.Add("pmFoto")
cols = dsFoto.Tables("pmFoto").Columns
col = cols.Add("sitenum")
col.Unique = False
col = cols.Add("thumb", System.Type.GetType("system.Byte"))
col.Unique = False
col = cols.Add("Foto", System.Type.GetType("System.byte"))
col.Unique = False

but I get a NULLEXCEPTION error message.

what do I need to do?

rg,
Eric
 
E

EMW

Thanks, but with this you already have a database filled with pictures and
the dataset table is based on that.

I start with nothing, so I have to make the dataset table.
That is were the problem starts.
How do I let the dataset know that the first column is a string, the second
will get a thumbnal (but that is just an image) and the third is the image
itself.

I think the second and third column needs to be set on Byte but how?

rg,
Eric
 
C

Cor

Hi Eric,

I asume this is the one you are looking for

col = cols.Add("thumb", System.Type.GetType("System.Byte[]"))

Cor
 
E

EMW

Yep, that was it. I didn't look at the uppercase letters and didn't know
about those brackets.
Thanks!


rg,
Eric
 
J

Jay B. Harlow [MVP - Outlook]

Eric,
Read the article from Cor again.

Item #6 shows you how to put (replace actually) the image into the database.

Item #7 shows you how to get the image from the database.


As to for the original question:

Your "type" is wrong.

col = cols.Add("thumb", System.Type.GetType("system.Byte"))

You are creating a column that holds a single byte, you need to create a
column that holds an array of bytes, try:

col = cols.Add("thumb", System.Type.GetType("System.Byte[]"))
col = cols.Add("Foto", System.Type.GetType("System.Byte[]"))

Alternatively I normally use:
col = cols.Add("thumb", GetType(System.Byte()))
col = cols.Add("Foto", GetType(System.Byte()))

As GetType(System.Byte()) does compile time checking while,
System.Type.GetType("System.Byte[]") does runtime checking (if you have an
error in the string itself, such as "Sys.Byt[]", you find out at runtime not
compile time).

Hope this helps
Jay
 
E

EMW

Thanks.

I got it working!

rg,
Eric

Jay B. Harlow said:
Eric,
Read the article from Cor again.

Item #6 shows you how to put (replace actually) the image into the database.

Item #7 shows you how to get the image from the database.


As to for the original question:

Your "type" is wrong.

col = cols.Add("thumb", System.Type.GetType("system.Byte"))

You are creating a column that holds a single byte, you need to create a
column that holds an array of bytes, try:

col = cols.Add("thumb", System.Type.GetType("System.Byte[]"))
col = cols.Add("Foto", System.Type.GetType("System.Byte[]"))

Alternatively I normally use:
col = cols.Add("thumb", GetType(System.Byte()))
col = cols.Add("Foto", GetType(System.Byte()))

As GetType(System.Byte()) does compile time checking while,
System.Type.GetType("System.Byte[]") does runtime checking (if you have an
error in the string itself, such as "Sys.Byt[]", you find out at runtime not
compile time).

Hope this helps
Jay

EMW said:
Thanks, but with this you already have a database filled with pictures and
the dataset table is based on that.

I start with nothing, so I have to make the dataset table.
That is were the problem starts.
How do I let the dataset know that the first column is a string, the second
will get a thumbnal (but that is just an image) and the third is the image
itself.

I think the second and third column needs to be set on Byte but how?

rg,
Eric



have
 

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

Top