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);