|
Project Information
Members
Featured
Downloads
Links
|
This utility makes it easy to create serialized XML DataSet's based on SQL queries run against a SQL Server.
You now have a way to mock a DataSet that would normally be loaded from a database. How to deserialize the DataTable: /// <summary>
/// Reads a <see cref="DataTable"/> from an embedded XML
/// document that contains the serialized version.
/// </summary>
/// <param name="sourceAssembly">
/// The assembly that contains the embedded file containing
/// the XML.
/// </param>
/// <param name="resourceName">
/// The qualified name of the resource to load.
/// </param>
/// <returns>
/// The reconstituted <see cref="DataTable"/>.
/// </returns>
public static DataTable ReadEmbeddedDataTable(Assembly sourceAssembly, string resourceName)
{
using (Stream readStream = sourceAssembly.GetManifestResourceStream(resourceName))
{
XmlSerializer xs = new XmlSerializer(typeof(DataSet));
DataSet ds = (DataSet)xs.Deserialize(readStream);
return ds.Tables[0];
}
}Related Blog Posts: |