473,665 Members | 2,774 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

problem updating table with varbinary(max) field from xml

2 New Member
Here's my problem.

I have a client application that uses a web service for data access. I can read/update many records in many tables, however, I am not getting what I expect for a varbinary(max) field I am trying to update.

Here's how I'm doing it.

I have a strongly typed dataset in c#. The column in question is defined as

System.Byte[] LogoImage,

for a simple test, I store a single byte with a zero value in this column. In the debugger, it looks correct.

I then call myDataSet.GetXm l() to convert to XML so I can send to my web service.

When I look at the XML string getting sent to the web service the column looks like this:

<LogoImage>AA== </LogoImage>

When I step into my web service code, I still see the xml looking the same:

<LogoImage>AA== </LogoImage>

I then eventually call a stored procedure to update the record. It passes the xml string as a parameter to the stored procedure:

--Here are the relevent parts of the stored procedure
--with other fields cut out so as not to confuse

ALTER PROCEDURE [dbo].[usp_myUpdateRou tine_u]
-- Add the parameters for the stored procedure here
@InstitutionRec ID int = 0,
@UserID varchar(20) = NULL,
@XML xml = NULL

-- then it later does this code to do the update

EXEC sp_xml_prepared ocument @idoc OUTPUT, @XML

Update [dbo].[mytable]
set [LogoImage] = xdoc.[LogoImage]

FROM OPENXML (@idoc, 'Data/CheckingAccount Def/CheckMain', 2 )
with (
[LogoImage] varbinary(max)
) xdoc;

EXEC sp_xml_removedo cument @idoc


after the update statement, I can do a select statement on the table and see in that column there is a value of:

0x410041003D003 D00

Any idea what is happening?

Then, when I call another stored procedure to read that record and send back to my client application, the field in XML looks like this:

<LogoImage>QQBB AD0APQA=</LogoImage>


I'm thinking it's some sort of encoding issue.

I'm pretty new to C# and MSSQL, only been using for 4 months.

I would appreciate any thoughts or suggestions.

thanks

Quinton
Nov 24 '09 #1
1 6429
quintonmartin
2 New Member
Ok, I figured out what's going on.

byte[] testing = Convert.FromBas e64String("AA== ");
//testing is now a 1 byte array with a zero.

So, GetXml() is converting the binary data to base64 automatically.

However, in SQL Server, this base64 string is getting encoded AGAIN.

At the bottom of the page at this link, it describes how to convert the base64 string in XML back to binary data to be stored in the database.

http://msdn.microsoft.com/en-us/libr...7(SQL.90).aspx

Quinton
Nov 25 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
2465
by: vool | last post by:
Hi All Can anyone help with this please. I need a way of putting say 10 to 20 bullet points in one table field in an Access database - say seperate them with a special character, then build a bulletted list on my page. If I can get the page to detect each special character, insert a new bullet
5
26441
by: Mike | last post by:
Hi guys, For some reason, max-width isn't working on my computer. It's probably a minor syntax error on my part, but I just want to be sure. I'm running IE 6.0.2800.1106 SP1, my resolution is set to 1152x864, and the browser is maximized. In an external CSS file, I have: table { max-width: 1024px }
10
2748
by: MLH | last post by:
I have an A97 table with a Yes/No field named TowJob and a form bound to that table. The TowJob control on the form is bound to the same field. It is an option group with Yes and No bttns valued at -1 and 0 respectively. Unless I specifically set the table field's defaultvalue to Null, the form comes up with an automatic value of 0 in the control? The control has NO default value property setting. Why is that?
2
7978
by: Greg Strong | last post by:
Hello All, Is it possible to change table field lookup properties in code? I've been able to change other field properties in code, however so far no luck with field lookup properties. What I've done for test purposes is use a text input file for the table field lookup properties. I thought that I'd start first by just changing the 'Display Control' property. Thanks to Allen Browne for some ideals per...
2
6535
by: Bill Nguyen | last post by:
I need sample code to insert binary file (mappoint map file) into a varbinary column using VB.NET. Please help! Thanks Bill
2
2756
by: mukesh | last post by:
Can we use expression in default value for a table field for example – IIf(Table-1.field-1=table-2 . field-1, table-1.field-2, 0) Interpretation – If field-1 of table -1 is like/equal to field-2 of table-2 then value of field-1 of table-1 will be the default value other wise 0 will be the default value Can I use this type of conditional default value if yes please tell me how. I tried to set this expression in default property of a...
2
4776
by: tindersticks | last post by:
Hi Can someone please post the simplest script that will allow an asp page read and write to/from m a MS SQL varbinary(max) field. ie image or doc/pdf etc is converted to relevant format and inserted to the field and then read back and converted to original format. If you can do this - may your children be superheroes
4
4717
by: Martin Horst | last post by:
Hi, I've got an application which is written in .Net 1.1. When I try to write a varbinary(max) field using the SqlCommand and SqlParameter classes I got an exception like this: "The conversion of varchar into varbinary is invalid". When I remove this field from my update statement, everything works fine. The SQL paramter got the the DbNull value.
3
2991
by: adiel_g | last post by:
Hello everyone, I am trying to move a field name to a variable in vb.net. For example, first I retrieve the record from the database and save its value: .... userGroup = ds.Tables("Default").Rows(x).Item("UserGroupAccess").ToString 'retrive access value from dataset ....
0
8348
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
8863
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...
1
8549
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,...
0
8636
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6187
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
4356
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2765
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
2
2004
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1761
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.