473,466 Members | 1,400 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Picurebox SQL issue...

Need to grab an image off the disk, preview in a picturebox, then save
in SQL database for later viewing, etc.

Got the "grab/preview" part working fine, and *something* is being
stored in the SQL database, but when I go to retrieve the image and
place it in the picture box, the picture is blank. SQL datatype is
image, and the tableadapter has an update query that accepts the image
field and primary key. Image field is sent as a byte array. Length
of the image in SQL is 2 bytes more than the file on disk.

So, in trying to debug....

I've found that if I do a picturebox.image.save("c:\saved.tif",TIFF)
it saves it just fine, and the resultant image file on disk is
readible. But, if I do:

picturebox.image.save(memoryStream,TIFF)
memoryStream.read(byteArray,0,memoryStream.length)
system.io.file.writeAllBytes("c:\bytes.tif",byteAr ray)

the resultant file on disk is not a readible TIFF image.

....which makes me wonder how I'm supposed to convert BLOB data for
storage and retrieval in SQL. I've read through many articles which
suggest that I should:

dim byteArr(imageContent.length)
imageContent.read(byteArr,0,imageContent.length)
tableAdapter.updateQuery(byteArr,primaryKey)

where imageContent is system.io.fileStream and is initialized to
system.io.file.openRead(filePathOnDisk).

And it *appears* to work - well, it stores *something* in the SQL
database, but whatever it's storing is illegible. And when I try the
same series of steps but save to disk, it's also not recognizable as a
TIFF file.

Which takes me back to the question - how do I get BLOB data (TIFF or
other image/picture data) into SQL so that I can extract it back from
SQL and view it in a picturebox (VB.Net 2.x)?

Jul 5 '07 #1
2 1374
Hi Tracy -

Have you tried adding an additional column to the database to store
the original byte count? You can use that when you're converting the
data back.

In my experience, though, the best answer is to avoid database storage
of binary data alltogether. I've always run into strange quirks like
these.

I don't know anything about the problem domain/architecture you're
currently working with, but I've found that you're typically better
off saving the file outside of the database and accessing it via
either a web share, a shared folder, a webservice, or an RPC call.
Typically, on the server, I change the file names to match the primary
key of the row that it's referring to (typically a guid), and store
the original file name in the database for renaming on-the-fly later
(if desired). This avoids any filename collisions.

It will take a little more programming on your end to make sure that
the file system coincides with the database, but it will avoid these
kinds of bugs...

Good Luck,

-Mark

Jul 5 '07 #2
Kept banging my head against the wall, and here's what I came up with.

Dim byteArr2(Me.imageContent.Length) As Byte
' convert stream to byte - the hard way, because the .read
and .write operations don't seem to work
Dim aByte As Byte
Dim x1 As Integer
For x1 = 0 To Me.imageContent.Length - 1
Me.imageContent.Seek(x1, IO.SeekOrigin.Begin)
aByte = Me.imageContent.ReadByte
byteArr2(x1) = aByte
Next
tableAdapter.updateImage(byteArr2, primaryKey)

That will get the data into SQL in a format that can be retrieved and
displayed. Here's how to get it out:

Dim aTable As myDataTable
Dim aTableRow As myDataTableRow
aTable=tableAdapter.getByPKEY(primaryKey)
For Each aTableRow In aTable
Dim aStream As New
System.IO.MemoryStream(aTableRow.imageColumn) ' <-- this was the trick
Me.PictureBox1.Image = Image.FromStream(aStream)
Next

I originally had:

dim aStream as system.io.stream
aStream=new system.io.memoryStream
aStream.write(aTableRow.imageColumn,0,aTableRow.im ageColumn.length)

but that gave me "invalid parameter" or something on the
image.fromStream(aStream) line.

Anyone have any idea why it works one way and not the other? And, is
that a bug, or a feature? :)

Jul 5 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Paul Mateer | last post by:
Hi, I have been running some queries against a table in a my database and have noted an odd (at least it seems odd to me) performance issue. The table has approximately 5 million rows and...
7
by: George Hester | last post by:
Please take a look at this google artcle: http://groups.google.com/groups?hl=en&lr=&frame=right&th=55d6f4b50f5f9382&seekm=411f370d%241%40olaf.komtel.net#link9 The op was having trouble with...
2
by: Anthony Cuttitta Jr. | last post by:
We have an application that outputs several different graphs from data downloaded from our AS400. The application has worked without (this) issue for several months now, but just recently, the...
0
by: Kevin Spencer | last post by:
Hi all, I am working on a service that uploads METAR weather information to the National Weather Service FTP site. The service I'm authoring is hosted on a Windows 200 server, and the NWS FTP...
2
by: Ben Rush | last post by:
Hello World, Okay, I have spent the day browsing the newsgroups and reading up on article after article concerning ViewState corruption and so forth, and I have a couple questions. We...
5
by: Robert | last post by:
I have a series of web applications (configured as separate applications) on a server. There is a main application at the root and then several virtual directories that are independant...
0
by: Charles Leonard | last post by:
I am having yet another issue with Windows Server 2003. This time, the web service (a file import web service) appears to run except for one odd message: "ActiveX component can't create object". ...
3
by: **Developer** | last post by:
I have a usercontrol that contains two pictureboxes One is on top of the other. The bottom one is the parent of the top one. The top one is transparent. I invalidate the top one often
4
by: Paul | last post by:
Hi, I've been struggling with this today, I'm developing a DotNet2.0 website in C# that needs to call a long running data query. Obviously this is a good candidate for an Asynchronous call, so...
13
by: SAL | last post by:
Hello, I'm trying to include a popup in the ItemTemplate of a gridview row. The ItemTemplate for the field contains a textbox and when the user clicks in the textbox I want a popup panel to show...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
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...
1
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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...
0
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...
0
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 ...

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.