473,408 Members | 2,813 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,408 software developers and data experts.

Working with datatable.


I have a DataTabel object filled with table data from a database.

The table contains rows that have the same data in a particular column.
How can i make a new copy of the datatable removing the repeating rows?

Many thanks in advance
JB
Nov 16 '05 #1
5 6550
Hi Jensen,

Create a DataView for the original DataTable sorted by that column. Create a
new DataTable you'll be inserting rows to. Start from the first DataView's
row, adding a new row to the destination table with all the data from the
source row. Then skip all rows having the same value in the column. Once the
value in the column changes, add this row and again skip further rows having
the same value. Do so until you've processed all rows in the view.

This is a off-the-top-of-my-head solution, I can't remember whether
DataTable's Select method supports the DISTINCT feature.

--
Sincerely,
Dmitriy Lapshin [C# / .NET MVP]
Bring the power of unit testing to the VS .NET IDE today!
http://www.x-unity.net/teststudio.aspx

"Jensen bredal" <je************@yahoo.com> wrote in message
news:eq**************@TK2MSFTNGP09.phx.gbl...

I have a DataTabel object filled with table data from a database.

The table contains rows that have the same data in a particular column.
How can i make a new copy of the datatable removing the repeating rows?

Many thanks in advance
JB


Nov 16 '05 #2
On Thu, 24 Feb 2005 12:33:11 +0100, Jensen bredal wrote:
I have a DataTabel object filled with table data from a database.

The table contains rows that have the same data in a particular column.
How can i make a new copy of the datatable removing the repeating rows?


This article gives you a method to do exactly what you want:
http://support.microsoft.com/default...b;en-us;326176
Nov 16 '05 #3
great ,

How could this be done in an sql statement if i could directly acces the
source table?

"Dmitriy Lapshin [C# / .NET MVP]" <x-****@no-spam-please.hotpop.com> wrote
in message news:u8*************@TK2MSFTNGP10.phx.gbl...
Hi Jensen,

Create a DataView for the original DataTable sorted by that column. Create
a new DataTable you'll be inserting rows to. Start from the first
DataView's row, adding a new row to the destination table with all the
data from the source row. Then skip all rows having the same value in the
column. Once the value in the column changes, add this row and again skip
further rows having the same value. Do so until you've processed all rows
in the view.

This is a off-the-top-of-my-head solution, I can't remember whether
DataTable's Select method supports the DISTINCT feature.

--
Sincerely,
Dmitriy Lapshin [C# / .NET MVP]
Bring the power of unit testing to the VS .NET IDE today!
http://www.x-unity.net/teststudio.aspx

"Jensen bredal" <je************@yahoo.com> wrote in message
news:eq**************@TK2MSFTNGP09.phx.gbl...

I have a DataTabel object filled with table data from a database.

The table contains rows that have the same data in a particular column.
How can i make a new copy of the datatable removing the repeating rows?

Many thanks in advance
JB

Nov 16 '05 #4
Great article.

Many thanks...

JB
"Mehdi" <vi****@REMOVEME.gmail.com> wrote in message
news:17*****************************@40tude.net...
On Thu, 24 Feb 2005 12:33:11 +0100, Jensen bredal wrote:
I have a DataTabel object filled with table data from a database.

The table contains rows that have the same data in a particular column.
How can i make a new copy of the datatable removing the repeating rows?


This article gives you a method to do exactly what you want:
http://support.microsoft.com/default...b;en-us;326176

Nov 16 '05 #5
Jensen,
How could this be done in an sql statement if i could directly acces the
source table?


Almost exactly as Dimitry says using the Select Distinct.

The Net system.data namespace does not support a Distinct, the method that
Mehdi shows and Dimitry suggest in this thread is in my opinion as well the
best method for is. (Be aware that the showed method does only move one
field, you can of course do more fields and than count)

I hope this helps

Cor

Nov 16 '05 #6

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

Similar topics

9
by: Bob Achgill | last post by:
I would like some example code that shows retrieving and updating selected column data from a DataTable. I am sucessful to load and select the whole row of a DataTable into a datagrid. But...
1
by: jimb | last post by:
I can get the dropdownlist into the datagrid, and I can populate it, but I can't read it. Anybody have a working example of a dropdownlist in an editable grid? Thanks. -- .....
5
by: George | last post by:
I have set DataAdapter.AcceptChangesDuringUpdate = true; However, I find that I still need to call AcceptChanges on the associated DataTable, DataTable.AcceptChanges(); Has anyone...
1
by: matt | last post by:
hello, i have a web app that allows users to query our oracle db and produce a dataset of report data. they then have the option to serialize this data and store it in the database. later, then...
3
by: UJ | last post by:
I've got a working web service that we are moving to another machine and now I suddenly get the following error. While transferring the files, got the following message:...
4
by: Tomasz Jastrzebski | last post by:
Hello Everyone, I have a GridView control bound to a plain DataTable object. AutoGenerateEditButton is set to true, Edit button gets displayed, and RowEditing event fires as expected.
4
by: =?Utf-8?B?cmFuZHkxMjAw?= | last post by:
I'm working in Visual Studio 2005 and C#. I have a DataTable with many rows. The user can delete a row. After the row is deleted, I'd like to column values for the deleted row, but any attempt to...
0
jas16183
by: jas16183 | last post by:
Hi Guys, need some help here, Im working on a project in vb.net, the problem im facing is that my tableadapter.update(dataset.datatable) is not functioning, the datatable has a relation with...
11
by: lenygold via DBMonster.com | last post by:
Hi everybody! This query is supposed to count consecutive years from the current year without OLAP. Input Table: ID DateCol 1 02/01/2006 1 01/01/2006 1 01/01/2005
1
by: Sukh | last post by:
Hi All, Can anyone help me to understand this. please see the code: private fun1(){ int count1, count2; string strTest; DataTable dt = new DataTable();
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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,...
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...

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.