473,320 Members | 1,946 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

C#-ADO.NET and XML: Reading a byte[ ] from a dataset in its XML representation

Hello all. :)

My name is Oscar and I’m a novice on XML and dataset arguments.

I need some help to resolve (and understand :) ) the following problem:

I have stored some data in a SqlServer database. I read data stored in database using a DbDataAdapter which fill a dataset.
One of the columns DataType of the dataset is a System.Byte[ ] containing an array of bytes. (In the SqlServer database it is stored as VarBinary field).

For example: Byte[] _binaryCmd =0x15,0x00,0xFF,0xFF,0x12,0x5D,0x81,
0xD5,0x00,0xAB,0x00,0x00,0x00,0x01,0x00,0x00,0x00, 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};

I read the Xml representation of the data stored in the dataset, using the GetXml() methods, but I’m not able to read the value of the Byte[ ] field. These seems converted in some way. For example in the Xml element I read:

<BinaryCmd>FQD//xJdgdUAqwAAAAEAAAD///////8=</BinaryCmd>

Whereas if I read the field of the dataset I can read correctly the byte array:

0x15,0x00,0xFF,0xFF,0x12,0x5D,0x81,0xD5,0x00,0xAB, 0x00,0x00,0x00,0x01,0x00,0x00,0x00,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF

The same situation happen if I put the dataset in an XmlDataDocument.

Please someone could explain me as I can obtain the original value of the Byte[ ] field in the XML representation?

Many thanks in advance. :)


This is an extract of my C# code

DataSet exportDataSet = new DataSet();
exportDataSet.DataSetName = "ExportedData";

/// Set the sql query to read data (_rCmd is a DBCommand object)
_rCmd.CommandText = String.Format(_getPagedMessagesTemplate, _msgTableName, pageIndex, pageSize);

/// Define adapter select command _wAdapter is a DbDataAdapter ///object.
_wAdapter.SelectCommand = _rCmd;

/// fill the dataset
_wAdapter.Fill(exportDataSet, _msgTableName);

/// Create an XmlDataDocument object related to our Dataset
XmlDataDocument xmlDataDoc = new XmlDataDocument(exportedData);

/// build an XmlTextWriter. destinationFile is a String that /// contains the path of the xml destination file.
XmlTextWriter xmlWriter = new XmlTextWriter(destinationFile,Encoding.Default);

/// Write data on the xml destination file
xmlDataDoc.WriteTo(xmlWriter);
May 9 '07 #1
0 1646

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

Similar topics

0
by: arshad | last post by:
Hi, I am facing some problems in reading XML file into dataset in vb.net. The XML is having some duplicate tabels. I am getting the error message saying "The same table(imei_details) cannot be...
1
by: John | last post by:
Hi All, When I delete the last record from my dataset and then WriteXML() to the file; the Table itself, in the xml file, is removed. I need to prevent the table structure from being deleted if...
2
by: | last post by:
I've just started using managed extensions to write a web service, the learning curve seems pretty steep! Currently I'm stuck at this bit: my web service gets a String * of XML data. I want to...
2
by: Li Zhang | last post by:
I have a problem with reading byte from a memory stream. Basically I want to resize a image and then store them to sql server. Here is part of the codes. every time I tried to read byte from...
0
by: Onur Bozkurt | last post by:
Can anyone compare the performance when reading xml files with dataset first and then displaying the user and when parsing the xml files in other ways (xmldom vs...)
7
by: postings | last post by:
Hi - can you help please? Please review the following straightforward code which works fine with ordinary XML files. ---------------------------------------------------------------- Dim...
1
by: clickbidur | last post by:
I have a xml document as follows <Variables> <Email>abc@xyz.com</Email> <Status>ENABLED</Status> <UserDetails ID="21"> <Name> <Title>Mr.</Title> <FName>John</FName> <MName>M</MName>
0
by: Steve G | last post by:
I have an XML file from a client that I generated a schema from. I Open a DataSet and read the schema to get the tables and relationships. I write my tables and fields and assign parent rows etc. ...
2
by: John Devlon | last post by:
Hi, Does anyone have any examples on how to read an xml file into a DataSet ? How to update and write an XML-file from a DataSet? Many thanx John
1
by: jaleel | last post by:
I want to read an xml file which lots has nodes like this: <Add Key="I105" Source="FileNet - GetFileValues" Message="Value is obtained"/> I want to use the values corresponding to any keys in...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

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.