[Mono-bugs] [Bug 75395][Wis] New - Issuing a RowFilter on a DataView against a DateTime column a System.InvalidCastException is thrown

bugzilla-daemon at bugzilla.ximian.com bugzilla-daemon at bugzilla.ximian.com
Mon Jun 27 17:21:46 EDT 2005


Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by tjfontaine at gmail.com.

http://bugzilla.ximian.com/show_bug.cgi?id=75395

--- shadow/75395	2005-06-27 17:21:46.000000000 -0400
+++ shadow/75395.tmp.25697	2005-06-27 17:21:46.000000000 -0400
@@ -0,0 +1,102 @@
+Bug#: 75395
+Product: Mono: Class Libraries
+Version: 1.1
+OS: GNU/Linux [Other]
+OS Details: Linux server1 2.6.10-1-686 #1 Fri Mar 11 03:55:46 EST 2005 i686 GNU/Linux
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Wishlist
+Component: Sys.Data
+AssignedTo: mono-bugs at ximian.com                            
+ReportedBy: tjfontaine at gmail.com               
+QAContact: mono-bugs at ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: Issuing a RowFilter on a DataView against a DateTime column a System.InvalidCastException is thrown
+
+Please fill in this template when reporting a bug, unless you know what you
+are doing.
+Description of Problem:
+When trying to issue a RowFilter on a DataView against a DateTime column a
+System.InvalidCastException is thrown.
+
+Steps to reproduce the problem:
+1. Compile the following Program
+
+using System;
+using System.Data;
+
+public class Foo
+{
+        public Foo() {}
+        public static void Main(string[] args)
+        {
+                DataTable dt = new DataTable();
+                dt.Columns.Add("StartDate", typeof(DateTime));
+
+                DataRow dr;
+                DateTime date = DateTime.Now;
+
+                for(int i = 0; i < 10; i++)
+                {
+                        dr = dt.NewRow();
+                        dr["StartDate"] = date.AddDays(i);
+                        dt.Rows.Add(dr);
+                }
+
+                DataView dv = dt.DefaultView;
+                dv.RowFilter = "StartDate >= '" + DateTime.Now.AddDays(2) +
+"' and StartDate <= '" + DateTime.Now.AddDays(4) + "'";
+
+                Console.WriteLine("Rows in Table {0}", dt.Rows.Count);
+                Console.WriteLine("Rows in View {0}", dv.Count);
+        }
+}
+
+2. Run it
+3. 
+
+Actual Results:
+Unhandled Exception: System.InvalidCastException: Cannot cast from source
+type to destination type.
+in <0x00034> System.Globalization.DateTimeFormatInfo:GetInstance
+(IFormatProvider provider)
+in <0x00031> System.DateTime:Parse (System.String s, IFormatProvider fp,
+DateTimeStyles styles)
+in <0x00016> System.DateTime:Parse (System.String s, IFormatProvider fp)
+in <0x0002e> System.Convert:ToDateTime (System.String value,
+IFormatProvider provider)
+in <0x00014> System.String:System.IConvertible.ToDateTime (IFormatProvider
+provider)
+in <0x005d4> System.Convert:ToType (System.Object value, System.Type
+conversionType, IFormatProvider provider)
+in <0x00032> System.Convert:ChangeType (System.Object value, System.Type
+conversionType)
+in <0x00381> Mono.Data.SqlExpressions.Comparison:Compare (IComparable o1,
+IComparable o2, Boolean caseSensitive)
+in <0x00198> Mono.Data.SqlExpressions.Comparison:EvalBoolean
+(System.Data.DataRow row)
+in <0x00084> Mono.Data.SqlExpressions.BoolOperation:EvalBoolean
+(System.Data.DataRow row)
+in <0x00046> System.Data.Common.Key:GetRecord (System.Data.DataRow row)
+in <0x0010e> System.Data.Common.Index:RebuildIndex ()
+in <0x00016> System.Data.Common.Index:EnsureArray ()
+in <0x0000d> System.Data.Common.Index:get_Array ()
+in <0x0000d> System.Data.Common.Index:GetAll ()
+in <0x00152> System.Data.DataView:UpdateIndex (Boolean force)
+in <0x000e9> System.Data.DataView:set_RowFilter (System.String value)
+in <0x00214> Foo:Main (System.String[] args)
+
+
+Expected Results:
+The dataview successfully filtered out all but 2 days
+C:\Documents and Settings\TJ Fontaine>test.exe
+Rows in Table 10
+Rows in View 2
+
+How often does this happen? 
+Every time.
+
+Additional Information:


More information about the mono-bugs mailing list