How to serialize a DataRow ?

G

Guest

I have a DataRow that I need to send it to another process as a XML string by
remoting.
Bu I do not want the other process to be familiar with the schema or
DataTable and DataRow structure, so I tried to serialize it to a XML string
but I get an exception saying the DataRow as no public data.
The code I tried to use
XmlWriter writer = new XmlTextWriter(new System.IO.StringWriter());
// Throw an exception !
XmlSerializer serializer = new XmlSerializer(typeof(DataRow));
serializer.Serialize(writer, myDataRow);
string xmlStr = writer.ToString();
writer.Close();


Is there a way to convert a DataRow to an XML string ?
 
K

Kevin Yu [MSFT]

Hi Sharon,

The XmlSerializer requires the type of the object to be serialized has a
public default constructor like public DataRow(). However, the DataRow
doesn't have one. So in this case, we can only put the whole DataSet or
DataTable into an Xml doc and then get the row needed from the xml doc. Or
you can try the BinaryFormatter to serialize it instead. But in only
returns byte array instead of a string.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
K

Kevin Yu [MSFT]

Sorry, Sharon. But as far as I know, currently, no. Sorry for the
inconvenience.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top