Please help me to export a DataGrid to XML. I tried two ways but both cause exceptions to be thrown.
DataTable dt = (DataTable)dataGrid2.DataSource;
dt.WriteXml("t.xml", XmlWriteMode.IgnoreSchema);
This throws an InvalidOperationException with message "Cannot serialize the DataTable. DataTable name is not set."
Please recommend a suitable method to export a datagrid to XML.
Given that error; just set the DataTable's name?
Personally, I'd use object-serialization (perhaps
XmlSerializer
overList<T>
), butDataTable
should be fine...Update; for an example using
DataTable.WriteXml
/ReadXml
; note the "THIS LINE MAKES IT ALL WORK" comment; this is necessary a: to be able to write, and b: to read the rows correctly.