Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Stored proc to save bytearray into varbinary(max)

Author  Topic 

littlewing
Starting Member

33 Posts

Posted - 2008-10-23 : 13:43:53
Hi all, I have the following table:

CREATE TABLE [dbo].[fbForm](
[FormID] [int] IDENTITY(1,1) NOT NULL,
[SiteID] [int] NULL,
[FormXML] [xml] NULL,
[FormBinary] [varbinary](max) NULL,
CONSTRAINT [PK_fbForm] PRIMARY KEY CLUSTERED

I have the following (partial) stored proc code to save a byte array from my data layer (ADO.Net)

....

@siteID int,
@formXML xml,
@formBinary varbinary(MAX),

INSERT INTO fbForm (SiteID, FormXML, FormBinary)
VALUES (
@siteID,
@formXML,
0x
);

SET @FormID = @@IDENTITY;


UPDATE fbForm
SET FormBinary.Write (@formBinary, 0, DATALENGTH(FormBinary))
WHERE FormID = @FormID

This is my first attempt at using varbinary(max) and I grabbed some of this code from other posts but I can't seem to be able to save anything from @formBinary into FormBinary column. It doesn't overwrite
0x.

Can anyone tell me the correct method of handling varbinary(max) data? I'm trying to save a serialized object into this column in a SQL Server 2005 Express database.

Thank you.

hanbingl
Aged Yak Warrior

652 Posts

Posted - 2008-10-23 : 14:16:04
Everything seem Okay...

Have you tested your SP in SSMSEE??
Go to Top of Page

littlewing
Starting Member

33 Posts

Posted - 2008-10-23 : 14:23:50
Yes, I just did and lo and behold it worked fine. Lesson learned...

Thank you.
Go to Top of Page
   

- Advertisement -