Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Please include the line number of the error next time... as that helps.<br> It seems that you're assigning a string to the DataType property of DataColumn, which expects a Type object. So the fix would be...</p> <pre><code>dw.Table.Columns["RequiredDate"].DataType = NewDate.GetType(); // or typeof(DateTime) </code></pre> <p>Update (for problem#2 - sort doesn't happen) Adapted from the code snippet from <a href="http://msdn.microsoft.com/en-us/library/system.data.dataview%28v=VS.71%29.aspx" rel="nofollow noreferrer">this MSDN Page</a> (look here for implementation of the helper methods). Formatting of the DataColumn should be the responsibility of the presentation layer/consumer. However if you really need to do this in the DataView - <a href="http://www.devnewsgroups.net/group/microsoft.public.dotnet.framework.adonet/topic37560.aspx" rel="nofollow noreferrer">link</a></p> <pre><code>private static void DemonstrateDataView(){ // Create one DataTable with one column. DataTable myTable = new DataTable("myTable"); DataColumn colItem = new DataColumn("item",typeof(DateTime)); myTable.Columns.Add(colItem); // Add five items. DataRow NewRow; for(int i = 0; i &lt;5; i++){ NewRow = myTable.NewRow(); NewRow["item"] = DateTime.Now.AddDays(-i); myTable.Rows.Add(NewRow); } myTable.AcceptChanges(); // Print current table values. PrintTableOrView(myTable,"Current Values in Table"); DataView secondView = new DataView(myTable); secondView.Sort = "item"; PrintTableOrView(secondView, "Second DataView: "); } </code></pre> <p>Output:</p> <pre><code>Current Values in Table 8/10/2010 11:34:28 AM 8/9/2010 11:34:28 AM 8/8/2010 11:34:28 AM 8/7/2010 11:34:28 AM 8/6/2010 11:34:28 AM Second DataView: 8/6/2010 11:34:28 AM 8/7/2010 11:34:28 AM 8/8/2010 11:34:28 AM 8/9/2010 11:34:28 AM 8/10/2010 11:34:28 AM </code></pre>
 

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