473,564 Members | 2,768 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.Collecti ons.Generic;
using System.Text;
using System.Data;

namespace ConsoleApplicat ion1
{
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.Diagnost ics.Debug.Asser t( t.Rows.Count == 1 && v.Count == 1
);

t.Reset();

CreateColumns1( t );
r = t.NewRow();
r["Col1"] = "abc";
t.Rows.Add( r );

System.Diagnost ics.Debug.Asser t( 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 9608
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.d ewrote in message
news:11******** *************@7 3g2000cwn.googl egroups.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.Collecti ons.Generic;
using System.Text;
using System.Data;

namespace ConsoleApplicat ion1
{
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.Diagnost ics.Debug.Asser t( t.Rows.Count == 1 && v.Count == 1
);

t.Reset();

CreateColumns1( t );
r = t.NewRow();
r["Col1"] = "abc";
t.Rows.Add( r );

System.Diagnost ics.Debug.Asser t( 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.d ewrote in message
news:11******** *************@7 3g2000cwn.googl egroups.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.Collecti ons.Generic;
using System.Text;
using System.Data;

namespace ConsoleApplicat ion1
{
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.Diagnost ics.Debug.Asser t( t.Rows.Count == 1 && v.Count == 1
);

t.Reset();

CreateColumns1( t );
r = t.NewRow();
r["Col1"] = "abc";
t.Rows.Add( r );

System.Diagnost ics.Debug.Asser t( 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
9131
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 dataview to datatable). The dataview is being filtered. However when I assign it to the datatable it is not filtered. I put some debug code in...
1
6770
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" , MENU_ENTRY_ID = "MenuEntryId"; private void populateMenu() {
3
9795
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 aren't compatible data types. Does anyone have a suggestion on how to do this? My last resort is to create a new DataTable object and copy the rows...
7
9133
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 column. This table ends up with 386 rows. I need to loop through the smaller table and filter a DataView based on each row from this table. This...
1
5856
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
4436
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 dataview with a count = 0. Can someone explain why and how I might work around this problem? Here is the code for my function: Public Shared...
13
2081
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 the confusion......... I thought that the DataView is the view from the dataset, but it seems that the dataview has the records that are in the...
5
8818
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 happen. Dim objKeys(2) as Object objKeys(0) = "CL" objKeys(2) = 4000 Dim posView As DataView = New DataView(posDS.Tables("Positions"), _
4
1575
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 DropDownList on my page that filters the records that are displayed in the grid. How I'm currently handling this is when I initially bind, I...
0
7665
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7888
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7642
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6255
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5484
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5213
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
2082
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 we have to send another system
1
1200
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
924
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.