(All original content on this site is licensed under the Creative Commons License Attribution-Noncommercial-No Derivative Works 3.0.)

.NET DataSet dump (C#)

One thing that I really like about ColdFusion is the powerful cfdump.

Use the cfdump tag to get the elements, variables, and values of most kinds of ColdFusion objects. Useful for debugging. You can display the contents of simple and complex variables, objects, components, user-defined functions, and other elements. 

Of all the tags in ColdFusion, cfoutput is probably the only tag that I use more.

Unfortunately, most other languages, JavaScript and .NET included, don't include this powerful, and versatile, functionality.

Here's what I've got if I want to dump the contents of a DataSet:


StringBuilder dataString = new StringBuilder();

try {
	DataSet dataSet = new DataSet();
	dataSet.ReadXml(Server.MapPath(@"DataSetDump.xml"));
	foreach (DataTable table in dataSet.Tables) {
		dataString.Append("<h2>" + table.TableName.ToString() + "</h2>");
		foreach (DataRow row in table.Rows) {
			foreach (DataColumn column in table.Columns) {
				dataString.Append("Column <strong>" + column.ToString() + "</strong> = " + row[column].ToString() + "<br />");
			}
		}
	}
} catch (Exception ex) {
	Response.Write(ex.Message);
}

Whether this is the best way to do it, that's what I guess I'll find out, but it's been working well enough for my purposes.

See an example of this in use (on a simple XML file).

Tags: .net, c#

Categories: Internet, tutorials / guides

blog comments powered by Disqus

Archives