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

How to store image in strongly typed dataset

P: n/a
I'm caching a dataset in an asp.net session variable to hold a user's data.
one data item I need to store is an image the user uploaded. My problem is
that I don't know how to get the image into the dataset because I don't know
what datatype to set the dataset column and then set this image to. I saw
an example where someone defended a datatable in the global class and
defined the column as an object, however, when I define a strongly typed
dataset in the IDE there's no data type called object, binary, or byte().

For a start, here's how I'm getting the image data from the user
(ImageFileField is an inupt element type 'File' in the aspx):

Dim strm As Stream
strm = ImageFileField.PostedFile.InputStream
Dim lngLen As Long = strm.Length
Dim abytBuffer(CInt(lngLen - 1)) As Byte
strm.Read(abytBuffer, 0, CInt(lngLen))

So from here I have a memorystream object and a byte array both with the
image data. So now what do I do?

Thanks.

--
mo*******@nospam.com
Nov 20 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Define datacolumn with XSD data type base64Binary to store image

"moondaddy" wrote:
I'm caching a dataset in an asp.net session variable to hold a user's data.
one data item I need to store is an image the user uploaded. My problem is
that I don't know how to get the image into the dataset because I don't know
what datatype to set the dataset column and then set this image to. I saw
an example where someone defended a datatable in the global class and
defined the column as an object, however, when I define a strongly typed
dataset in the IDE there's no data type called object, binary, or byte().

For a start, here's how I'm getting the image data from the user
(ImageFileField is an inupt element type 'File' in the aspx):

Dim strm As Stream
strm = ImageFileField.PostedFile.InputStream
Dim lngLen As Long = strm.Length
Dim abytBuffer(CInt(lngLen - 1)) As Byte
strm.Read(abytBuffer, 0, CInt(lngLen))

So from here I have a memorystream object and a byte array both with the
image data. So now what do I do?

Thanks.

--
mo*******@nospam.com

Nov 20 '05 #2

P: n/a
Thanks! Thats exactly what I needed.

--
mo*******@nospam.com
"Rulin Hong" <Ru*******@discussions.microsoft.com> wrote in message
news:06**********************************@microsof t.com...
Define datacolumn with XSD data type base64Binary to store image

"moondaddy" wrote:
I'm caching a dataset in an asp.net session variable to hold a user's data. one data item I need to store is an image the user uploaded. My problem is that I don't know how to get the image into the dataset because I don't know what datatype to set the dataset column and then set this image to. I saw an example where someone defended a datatable in the global class and
defined the column as an object, however, when I define a strongly typed
dataset in the IDE there's no data type called object, binary, or byte().
For a start, here's how I'm getting the image data from the user
(ImageFileField is an inupt element type 'File' in the aspx):

Dim strm As Stream
strm = ImageFileField.PostedFile.InputStream
Dim lngLen As Long = strm.Length
Dim abytBuffer(CInt(lngLen - 1)) As Byte
strm.Read(abytBuffer, 0, CInt(lngLen))

So from here I have a memorystream object and a byte array both with the
image data. So now what do I do?

Thanks.

--
mo*******@nospam.com

Nov 20 '05 #3

P: n/a
New problem with this. Yes I can store an image in a base64Binary column,
but when I'm stepping through the code and watching the values of variables
in the watch window, as soon as I assign the image to the dataset column,
the watch window says for the dataset: "Unable to evaluate expression".

Foe example, the text below was copied from the watch window. I put
ds.getxml as a watch:

ds.getxml "<dsCachedImages
xmlns="http://tempuri.org/dsCachedImages.xsd">
<tbImages>

<SessionID>hefuapb3rcwuzn45fzgeybml</SessionID>
<ImageId />
</tbImages>
</dsCachedImages>" String

then as soon as I assign the image, or rather the byte() variable holding
the image this is what I see in the watch window:

ds.getxml Unable to evaluate expression.

Actually the dataset is still OK as I can retrieve data from the dataset
including the image's byte array. But from this point forward I cant see
into it from the watch window. furthermore, when I get errors, along with
the error information I also record the dataset's contents into the error
log using .getxml so I can see what the data looked like at the time of the
error. now that ds.getxml can not be evaluated, I can't record its contents
into the error log. I also tried converting the byte() into a string and
saving it to a string column in the dataset and got the same result. This is
how I did that:

Dim str As String = System.Text.Encoding.Default.GetString(abytBuffer)

and this is what the string looked like in the watch window:
str "#uExif String

so I appears that the string is still some of binary data which is confusing
the datase. I expected to get a much larger sting for an image 3k in size.

Is there a way to save an image to a dataset and still be able to use
ds.getxml on the dataset?


--
mo*******@nospam.com
"moondaddy" <mo*******@nospam.com> wrote in message
news:OJ**************@TK2MSFTNGP11.phx.gbl...
Thanks! Thats exactly what I needed.

--
mo*******@nospam.com
"Rulin Hong" <Ru*******@discussions.microsoft.com> wrote in message
news:06**********************************@microsof t.com...
Define datacolumn with XSD data type base64Binary to store image

"moondaddy" wrote:
I'm caching a dataset in an asp.net session variable to hold a user's data. one data item I need to store is an image the user uploaded. My problem
is
that I don't know how to get the image into the dataset because I
don't
know what datatype to set the dataset column and then set this image to. I saw an example where someone defended a datatable in the global class and
defined the column as an object, however, when I define a strongly
typed dataset in the IDE there's no data type called object, binary, or

byte().
For a start, here's how I'm getting the image data from the user
(ImageFileField is an inupt element type 'File' in the aspx):

Dim strm As Stream
strm = ImageFileField.PostedFile.InputStream
Dim lngLen As Long = strm.Length
Dim abytBuffer(CInt(lngLen - 1)) As Byte
strm.Read(abytBuffer, 0, CInt(lngLen))

So from here I have a memorystream object and a byte array both with the image data. So now what do I do?

Thanks.

--
mo*******@nospam.com


Nov 20 '05 #4

P: n/a
Hi,

I think this should be caused by the ds.GetXml() return a too long string
which exceed the capacity of watch window. The watch window is designed for
the debugging environment to display the values of variables, it is not
designed for holding a large string.

Imports System.IO
Module Module1
Sub Main()
Dim ds As New Dataset1
Dim fs As New FileStream _
("C:\test\TestPIC\Dollar.gif", FileMode.OpenOrCreate, _
FileAccess.Read)
Dim MyData(fs.Length) As Byte
fs.Read(MyData, 0, fs.Length)
fs.Close()
Dim myRow As DataRow
myRow = ds.TestTable.NewRow()
myRow(0) = "This would be description text"
myRow(1) = MyData
ds.TestTable.Rows.Add(myRow)
' I think we can try to use the debug.wrtieline to output the long string
or output the string to a file.
Debug.WriteLine(ds.GetXml())
fs = Nothing
ds = Nothing
End Sub
End Module

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 20 '05 #5

P: n/a
Thanks that answers it.

--
mo*******@nospam.com
""Peter Huang"" <v-******@online.microsoft.com> wrote in message
news:AW**************@cpmsftngxa06.phx.gbl...
Hi,

I think this should be caused by the ds.GetXml() return a too long string
which exceed the capacity of watch window. The watch window is designed for the debugging environment to display the values of variables, it is not
designed for holding a large string.

Imports System.IO
Module Module1
Sub Main()
Dim ds As New Dataset1
Dim fs As New FileStream _
("C:\test\TestPIC\Dollar.gif", FileMode.OpenOrCreate, _
FileAccess.Read)
Dim MyData(fs.Length) As Byte
fs.Read(MyData, 0, fs.Length)
fs.Close()
Dim myRow As DataRow
myRow = ds.TestTable.NewRow()
myRow(0) = "This would be description text"
myRow(1) = MyData
ds.TestTable.Rows.Add(myRow)
' I think we can try to use the debug.wrtieline to output the long string
or output the string to a file.
Debug.WriteLine(ds.GetXml())
fs = Nothing
ds = Nothing
End Sub
End Module

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 20 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.