A
am72de
Hi all,
I have a problem with the DataTable.Reset().
After resetting the DataTable the count of the DataView is no longer
equal with the DataTable.Rows.Count, so the second Assert fails.
See the simplified example below...
Does anybody has this behaviour too?
Does anybody know why this happens and how I can refresh the DataView?
Thanks in advance
Andy
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
DataTable t = new DataTable("test");
DataView v = new DataView( t );
CreateColumns1( t );
DataRow r = t.NewRow();
r["Col1"] = "abc";
t.Rows.Add( r );
System.Diagnostics.Debug.Assert( t.Rows.Count == 1 && v.Count == 1
);
t.Reset();
CreateColumns1( t );
r = t.NewRow();
r["Col1"] = "abc";
t.Rows.Add( r );
System.Diagnostics.Debug.Assert( t.Rows.Count == 1 && v.Count == 1
); //v.Count == 0
}
private static void CreateColumns1(DataTable t)
{
t.Columns.Add( "Col1" );
}
}
}
I have a problem with the DataTable.Reset().
After resetting the DataTable the count of the DataView is no longer
equal with the DataTable.Rows.Count, so the second Assert fails.
See the simplified example below...
Does anybody has this behaviour too?
Does anybody know why this happens and how I can refresh the DataView?
Thanks in advance
Andy
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
DataTable t = new DataTable("test");
DataView v = new DataView( t );
CreateColumns1( t );
DataRow r = t.NewRow();
r["Col1"] = "abc";
t.Rows.Add( r );
System.Diagnostics.Debug.Assert( t.Rows.Count == 1 && v.Count == 1
);
t.Reset();
CreateColumns1( t );
r = t.NewRow();
r["Col1"] = "abc";
t.Rows.Add( r );
System.Diagnostics.Debug.Assert( t.Rows.Count == 1 && v.Count == 1
); //v.Count == 0
}
private static void CreateColumns1(DataTable t)
{
t.Columns.Add( "Col1" );
}
}
}