473,411 Members | 2,031 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,411 software developers and data experts.

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 9587
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
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
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
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
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
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
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
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
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
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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...
0
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
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
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...

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.