473,499 Members | 1,593 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DataView and DataTable.Reset()

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" );
}
}
}

Dec 11 '06 #1
2 9597
Hi Andy,

I can't imagine why you'd want to do that. It makes more sense to me to
just create another DataTable, but I'll give you the benefit of the doubt ;)

Calling v.EndInit() seems to do the trick (event without a prior BeginInit
call)

--
Dave Sexton

<am****@yahoo.dewrote in message
news:11*********************@73g2000cwn.googlegrou ps.com...
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" );
}
}
}

Dec 11 '06 #2
Hi Dave,

thanks for your reply. Unfortunately this behaviour occur in a more
complex project, where the DataTable and the DataView are referenced by
several classes, it isn't possible to allocate a new DataTable. But
your EndInit works like a charme. Thanks for your assistance.

Andy

Dave Sexton schrieb:
Hi Andy,

I can't imagine why you'd want to do that. It makes more sense to me to
just create another DataTable, but I'll give you the benefit of the doubt ;)

Calling v.EndInit() seems to do the trick (event without a prior BeginInit
call)

--
Dave Sexton

<am****@yahoo.dewrote in message
news:11*********************@73g2000cwn.googlegrou ps.com...
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" );
}
}
}
Dec 12 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
9102
by: Dianna K. | last post by:
I have a dataview which I am assigning to a Datatable (I am doing this because currently Crystal Reports will not accept a dataview as a Reportsource -- The recommended work-around is to assign...
1
6761
by: GeraldBauer | last post by:
I am experiencing some weird behaviors with the listbox and dataview. Here is a boiled down code snippet of what I am trying to do. <snippet> string MENUID = "MenuId" , ITEM = "Item" ,...
3
9784
by: Brian Bischof | last post by:
I'm using a third-party tool that takes a DataTable as a parameter. I really need to pass it a DataView instead. When I try to explicitly cast the DataView as a DataTable I get an error that they...
7
9117
by: Joe | last post by:
Not sure what group this question is better suited for so I sent it to both. I have a DataTable which contains 1545 rows. I have a method that returns a DataTable of distinct rows based on one...
1
5845
by: TaeHo Yoo | last post by:
Hi all, After sorting and grouping data using a dataview, then how to transfer the changed datatable in the dataview to a datatable in C#? Cheers
36
4411
by: kjvt | last post by:
Based on a prior posting, I've written a function to convert a recordset to a dataview. The first call to the function for a given recordset works perfectly, but the second call always returns a...
13
2065
by: Steve | last post by:
I have a form with a dataset and a datagrid. I created a dataview on this dataset. When the user modifies the datagrid, I look up this record in the dataview to make sure it is unique. Here is...
5
8809
by: David Wender | last post by:
I want to create a dataview with a sort on multiple columns. However, when I use FindRows, I only want to search some of the columns, not all. Is this possible? I have not been able to make it...
4
1570
by: James | last post by:
Basically I have a DataGrid that I'm binding to the results of a stored procedure call. The recordset is fairly small. Initially I'm creating a DataSet from the results and binding it. There's a...
0
7132
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7223
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6899
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5475
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4919
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4602
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3094
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1427
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
302
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.