Groups | Blog | Home
all groups > sql server (alternate) > november 2004 >

sql server (alternate) : Insert a jpeg into a column sql server 2000 - desperately seeking help


rdshultz NO[at]SPAM nooter.com
11/12/2004 8:25:45 AM
I'm a complete newbie. Need to insert a Company logo into a database
column to use later on in a check printing application. Read how to
insert the pointer instead of the object into the column. Below is
what I did:

SET QUOTED_IDENTIFIER OFF
GO
INSERT INTO BankInfo
(CoLogo) VALUES(0xFFFFFFFF)

***Then I did this****

DECLARE @Pointer_Value varbinary(16)
Select @Pointer_Value = TEXTPTR(CoLogo)
FROM BankInfo
WHERE CMCo = '91'
WRITETEXT BankInfo.CoLogo @Pointer_Value
"\\192.31.82.77\Data\CheckImages\WyattLogo.jpg"

****This was straight out of a book and it seemed to work it gave me a
message that it was successful and when I view the data in the column
I can see the pointer
0x453A5C436865636B496D616765735C57796174744C6F676F2E6A7067*****

But when I try to use the column in either Crytal Report or an Access
Report the Bank Logo does not show up. I also placed the logo on my C
drive and tried pointing to it there with "C:\WyattLogo.jpg" with no
success.

It can't be this difficult to get a Company logo into a column. I
desperately need assistance. Remember I am the ultimate newbie. I
looked at my first sql database last week. Thanks in advance for any
Erland Sommarskog
11/12/2004 10:53:53 PM
rdshultz (rdshultz@nooter.com) writes:
[quoted text, click to view]

Alas, it is not that easy. What you have there, is some sort of
binary representation of the URL itselt. (Actually, it is not. This
is from your attempt to use C:\WyattLogo.jpg.) SQL Server is not going out
to access the web or your disk to read the JPEG for you. You need to say:

WRITETEXT BankInfo.CoLogo @Pointer_Value
0xFFD8FFE1D8454578...

Where the hex string is contents of the file itself. The "pointer" in
this context is a pointer with SQL Server, to the special area where the
value for this image column are stored.

So how would you do this in practice? Most commonly, I think people
use the ADO method AddChunk write a program that reads the binary
file and sends down in pieces. But you could of course also write a
program that constructs the entire SQL batch with hexstring and all.
(If you use AddChunk I don't think you need to convert to hexstring.)


--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server SP3 at
AddThis Social Bookmark Button