Microsoft
Software
Hardware
Network
Question : How to insert a single blob?
Hello,
I inserted a picture into an image field in SQL server using following query.
UPDATE dbo.Photo SET Document =
(SELECT * FROM
OPENROWSET(BULK 'C:\Pictures\Lighthouse.jp
g', SINGLE_BLOB) AS ORS)
When i render this image in an ASP.NET web page it works fine. I use this code block:
var photoQuery = (from inp in db.Photos
select new { Id = inp.ID, Document = inp.Document, Name = inp.ID });
foreach (var item in photoQuery)
{
Photo photo = new Photo();
byte[] picture = (byte[])(item.Document);
MemoryStream ms = new MemoryStream(picture);
System.Drawing.Image image = System.Drawing.Image.FromS
tream(ms);
photo.Listing_ID = item.Id;
photo.Name = item.Name.ToString();
using (var memoryStream = new MemoryStream())
{
image.Save(memoryStream, ImageFormat.Jpeg);
photo.Data = memoryStream.ToArray();
}
images.Add(photo);
}
until this point everything works fine.
but when i look in the field in SQL server i see a long binary hexidecimal string. These are the first few characters:
0xFFD8FFE000104A4649460001
0100000100
010000FFFE
003E43524
Now what i'm attempting to do is to copy that last piece of data as a string into the image field in SQL server. I test this by doing:
UPDATE dbo.tbl_InspectionPhoto set INP_Document =
'0xFFD8FFE000104A464946000
1010000010
0010000FFF
E003E43524
'
when i refresh my asp.net page, i get an error on System.Drawing.Image image = System.Drawing.Image.FromS
tream(ms):
The parameter is not valid.
Any help would be greatly appriciated.
Thanks in advance,
MA
Answer : How to insert a single blob?
Don't use quotes around the hex string. It is not a text string, but hex encoded binary data.
Random Solutions
Access VBA Word merge
Er diagram for university accommodation office
Trend Micro Officescan 10.0 on Citrix XenApp Presentation Server 4.5 or 5.0
How to clear a datagridview
Block, ban, remove ulrasurf
LUN unpresented from ESX hosts causing alarms
Crosstab Query To Excel - Number Format
Internet Explorer blocking javascript
MS Access 2007 -- Using Like with Left Join
How do create a Windows batch script to start a service and set to automatic