Currently, it is very convenient to store and read datatable data in XML. Here, we can help you to sum up that some complicated content is stored as an XML table and threw it into the text field.
Datatable is stored as XML
Create a table, a structure, and a writer.
Datatable dt = New Datatable ( " Matrixinfo " );
Datacolumn DC1 = New Datacolumn ( " Itemid " , Type. GetType ( " System. String " ));
Datacolumn DC2 = New Datacolumn ( " Itemname " , Type. GetType ( " System. String " ));
DT. Columns. Add (DC1 );
DT. Columns. Add (DC2 );
For ( Int I = 0 ; I < Al. Count; I ++ )
{
Datarow Dr = DT. newrow ();
Ds_option DSO = (Ds_option) al [I];
Dr [ " Itemid " ] = DSO. ID;
Dr [ " Itemname " ] = DSO. Name;
DT. Rows. Add (DR );
}
String Xmlstr;
System. Io. stringwriter writer = New System. Io. stringwriter ();
DT. writexml (writer );
Xmlstr = Writer. tostring ();
Return Xmlstr;
Reading is similar, but you must first create a datatable structure. Otherwise, errors will occur. String Tbxml = Xmlinfo;
Datatable dt = New Datatable ( " Matrixinfo " );
Datacolumn DC1 = New Datacolumn ( " Itemid " , Type. GetType ( " System. String " ));
Datacolumn DC2 = New Datacolumn ( " Itemname " , Type. GetType ( " System. String " ));
DT. Columns. Add (DC1 );
DT. Columns. Add (DC2 );
System. Io. stringreader Reader = New System. Io. stringreader (tbxml );
DT. readxml (Reader );