473,287 Members | 1,447 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 software developers and data experts.

How to store image in strongly typed dataset

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
5 10597
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: | last post by:
We have an object factory that returns weakly typed datasets (just plain ol' DataSet's). I need to cast it, or transform it, or map it to a strongly typed dataset. There's an old adage I heard...
2
by: theWizK | last post by:
Hello all. I have noticed that when I generate a strongly-typed dataset from an xml schema that the DataTables that are generated have their constructors marked as internal. What this means is...
1
by: Job Lot | last post by:
I am confused how strongly typed dataset is different from un-typed dataset. Is there any good link explaining pros and cons of both? Which one should be used preferably?
0
by: MT | last post by:
I have an xsd file that I use to create a strongly typed dataset in my project. In the past, I have used the ReadXml method to load xml files into the generated class and read data in using this...
7
by: Jeff | last post by:
I want to remote several strongly typed datasets and I don't want to distribute the assemblies. I wish to create interface assemblies for these datasets but I don't know where to start. I've...
0
by: jdipalmajr | last post by:
I noticed that I was getting performance issues when I referenced a strongly typed dataset using untyped references. When I changed my code to only use strongly typed references the performance...
2
by: David | last post by:
I have been developing applications with Java for quite a while but I am new to .NET development. I am trying to learn the ".NET way" of creating Strongly Typed Objects from a database. The...
1
by: Andre Ranieri | last post by:
I'm designing an extranet web site that customers will use to log in and see their account history, make payments against their balance, etc. I've declared a strongly typed DataSet as a public...
3
by: Programatix | last post by:
Hi. I'm using a strongly typed dataset and I would like to get the index number of a column from a datarow. Is that possible? I would like to avoid using expression like this, ...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.