Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I use this code...</p> <p>To generate the XML:</p> <pre class="lang-cs prettyprint-override"><code>// you need to create a datatable, from a sql query, linq, your choice... DataTable _dt = new DataTable(); // write the datatable with schema dt.WriteXml("datatable.xml", XmlWriteMode.WriteSchema); </code></pre> <p>To read the XML:</p> <pre class="lang-cs prettyprint-override"><code>DataTable dt = new DataTable (); dt.Clear(); dt.ReadXml("datatable.xml", XmlReadMode.ReadSchema); </code></pre> <p>The result datatable can be complemented with these functions, this way you can convert it to <code>IList</code>, you need to create an object with the same pattern of columns, it's really more practical this way:</p> <pre class="lang-cs prettyprint-override"><code>public IList&lt;T&gt; toList&lt;T&gt;(DataTable table) { List&lt;T&gt; list = new List&lt;T&gt;(); T item; Type listItemType = typeof(T); for (int i = 0; i &lt; table.Rows.Count; i++) { item = (T)Activator.CreateInstance(listItemType); mapRow(item, table.Rows[i], listItemType); list.Add(item); } return list; } private void mapRow(object vOb, System.Data.DataRow dr, Type type) { try { for (int col = 0; col &lt; dr.Table.Columns.Count; col++) { var columnName = dr.Table.Columns[col].ColumnName; var prop = type.GetProperty(columnName.ToUpper()); object data = dr[col]; prop.SetValue(vOb, data, null); } } catch (Exception ex) { throw ex; } } </code></pre> <p>Actually, I'm working on an app that use XML generated from SQL tables. Basically, use the functions above, I create other small app (to support the first one) that scan the package of XML (XML per table) and create the layers business, access, object and a flow control for proper writing &amp; reading of the XML.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload