Monday, February 2, 2009

C# DataTable with Custom Objects

Came across this little tidbit to allowing custom object types in a .net DataTable. Issue being that if you don't set the property, you get the string value of the object.

DataTable dt = new DataTable();
DataColumn dcMyObject = new DataColumn("MyObject");
dcMyObject.DataType = typeof("MyNameSpace.MyClass");
dt.Columns.Add(dcMyObject);

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.