How to serialize a DataRow ?

  • Thread starter Thread starter Guest
  • Start date Start date
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 ?
 
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."
 
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."
 
Back
Top