473,746 Members | 2,641 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Inpu tStream
Dim lngLen As Long = strm.Length
Dim abytBuffer(CInt (lngLen - 1)) As Byte
strm.Read(abytB uffer, 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*******@nospa m.com
Nov 20 '05 #1
5 10632
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.Inpu tStream
Dim lngLen As Long = strm.Length
Dim abytBuffer(CInt (lngLen - 1)) As Byte
strm.Read(abytB uffer, 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*******@nospa m.com

Nov 20 '05 #2
Thanks! Thats exactly what I needed.

--
mo*******@nospa m.com
"Rulin Hong" <Ru*******@disc ussions.microso ft.com> wrote in message
news:06******** *************** ***********@mic rosoft.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.Inpu tStream
Dim lngLen As Long = strm.Length
Dim abytBuffer(CInt (lngLen - 1)) As Byte
strm.Read(abytB uffer, 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*******@nospa m.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 "<dsCachedImage s
xmlns="http://tempuri.org/dsCachedImages. xsd">
<tbImages>

<SessionID>hefu apb3rcwuzn45fzg eybml</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.Enc oding.Default.G etString(abytBu ffer)

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*******@nospa m.com
"moondaddy" <mo*******@nosp am.com> wrote in message
news:OJ******** ******@TK2MSFTN GP11.phx.gbl...
Thanks! Thats exactly what I needed.

--
mo*******@nospa m.com
"Rulin Hong" <Ru*******@disc ussions.microso ft.com> wrote in message
news:06******** *************** ***********@mic rosoft.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.Inpu tStream
Dim lngLen As Long = strm.Length
Dim abytBuffer(CInt (lngLen - 1)) As Byte
strm.Read(abytB uffer, 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*******@nospa m.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\TestP IC\Dollar.gif", FileMode.OpenOr Create, _
FileAccess.Read )
Dim MyData(fs.Lengt h) As Byte
fs.Read(MyData, 0, fs.Length)
fs.Close()
Dim myRow As DataRow
myRow = ds.TestTable.Ne wRow()
myRow(0) = "This would be description text"
myRow(1) = MyData
ds.TestTable.Ro ws.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*******@nospa m.com
""Peter Huang"" <v-******@online.m icrosoft.com> wrote in message
news:AW******** ******@cpmsftng xa06.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\TestP IC\Dollar.gif", FileMode.OpenOr Create, _
FileAccess.Read )
Dim MyData(fs.Lengt h) As Byte
fs.Read(MyData, 0, fs.Length)
fs.Close()
Dim myRow As DataRow
myRow = ds.TestTable.Ne wRow()
myRow(0) = "This would be description text"
myRow(1) = MyData
ds.TestTable.Ro ws.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
2108
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 from a Microsoft developer a long time ago: If it's taking more than 10 lines of code, then you are doing it wrong. Is there an *easy* way to do this in a *generic* way? I have been experimenting with serveral techniques and
2
2888
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 when I try to instantiate one of the strongly-typed tables from this dataset from a different assembly, I cannot. Let me provide examples... If I have a simple dataset like this:
1
6088
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
1852
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 class. These files have now become big (order of 100MB) and this completely kills the readxml performance. I have read multiple posts that tell you not to use datasets for large files. I even tried calling BeginLoadTables before starting the...
7
7040
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 tried to use soapsuds, but this did not work correctly. I tried to use NMatrix XofG, but this seems very complicated. All I need is something that will convert a class file into an interface. Is there anything already built that will do this? ...
0
1024
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 was snappy. Why might this be the case? Seems like it should work either way. I am also using this dataset in a datagrid reference. Could the databinding be involved somehow?
2
4375
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 Enterprise Library seems pretty close to what I am used to in Java but I am not sure how to create strongly-typed DataSets. I see that I can use the LoadDataSet method from a Microsoft.Practices.EnterpriseLibrary.Data.Database but I am not clear on how...
1
1501
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 static object in the main accounts page - "public Customer.DataSet dsMyData = new Customer.DataSet();" and populate the tables with information about the account, services, etc which are referenced from the other pages as such: lblEMail.Text =...
3
8800
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, myTable.Columns.IndexOf("myColumnName") Thanks.
0
8974
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
8800
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9500
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9349
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9285
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6772
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Duprť who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6060
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4836
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3292
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.