C# - How To Get Distinct Records In Datatable

Jul 20, 2010

I am using C# + VSTS 2008 + .Net + ASP.Net + IIS 7.0 + ADO.Net + SQL Server 2008. I have a ADO.Net datatable object, and I want to filter out duplicate/similar records (in my specific rule to judge whether records are duplicate/similar -- if record/row has the same value for a string column, I will treat them as duplicate/similar records), and only keep one of such duplicate/similar records.

The output needs to be a datatable, may output the same datatable object if filter operation could be operated on the same datatable object.

What is the most efficient solution?

View 3 Replies


Similar Messages:

ADO.NET :: How To Get The Distinct Value Form DataTable Using LINQ

Oct 27, 2010

I would like to get the distinct value form DataTabel using LINQ.

For example my sample table,

[code]....

1. How to get the distinct Country from Country you like column and the return records as Array or DataTable? (I want only India,USA,UK,Germany )

Is there any way to filter the record values using LINQ?

View 3 Replies

Web Forms :: How To Check Distinct Val In Datatable

Jan 28, 2010

how can i check distinct val in col_1 of datatable and assign seq no to each distinct val of col_1 to col_2?

View 6 Replies

ADO.NET :: Distinct Values From A Column In Datatable?

Sep 21, 2010

I have a datatable dt with 4 columns. I want to retrieve only distinct values from column1 of datatable.

How can I achieve this using c# code?

View 3 Replies

Linq To DataTable Not Producing Distinct Values?

Oct 19, 2010

I have a datatable which has been dynamically generated from FoxPro tables using a UNION Select statement. e.g.

SELECT * FROM x UNION SELECT * FROM y UNION SELECT * FROM Z ORDER By v_alue1

This produces a datatable with about 100 rows, each containing many fields, one of which is c_olor. From this datatable, I would like to select the distinct colors and then output in a dropdown.

I have a public class Color which just has one property which I can then use as the DataTextField and DataValueField for the dropdownlist

[code]...

However this never results in the distinct colors.

I have searched and searched for what I am looking for, and this seems to be one of the methods to produce a distinct set of results, but this and the others do not work.

My reasoning behind getting the colors this way, is that I need to get various other distinct values from the same UNION SELECT datasource, so would just do one DB call, cache the results, and then just used this cached datasource to retrieve all my distinct values.

View 2 Replies

Using Select Distinct On An Already Created DataTable Object?

Nov 16, 2010

I have an already created DataTable object which i am using for my girdview (asp.net) i also need to bind a column of that object to a DropDownList. The datatable has the correct details in the column but the column contains more that 1 of the same name in the column - hence I would love to just do some kind of SELECT DISTINCT on the datatable and copy it to a new datatable for use with binding the dropdown.

This would allow me to save resources by making another trip to the database.

Here is an example, the current datatable has a column called items and in this column has the following entries

1
1
1
1
5
5
6

And of course i need only unique items for binding to my dropdown, hence i need the following data

1
5
6

Of course i don't want to change the original datatable object but rather make a copy of it will the new details.

View 2 Replies

Data Controls :: Copying Specific Records From One Datatable To Another Datatable

Aug 22, 2012

im trying to copying specific record from one datatable to another datatable i used below code

public System.Data.DataTable selectspecificdatarow(System.Data.DataTable dtg, int count, int startindex)
{
System.Data.DataTable dtn = dtg.Clone();
for (int i =startindex; i < count; i++)

[Code]....

its taking too long time in cloneing is there any better way to do this task which is Time effecent

View 1 Replies

DataSource Controls :: How To Get Records In 1st DataTable But Not In 2nd DataTable

May 14, 2010

I have two datatables, I want to get all records which are in one datatable but all matching records which exist in another datatable should not be available.

In terms of set, you can say that record which are in 1st datatable but not in 2nd DataTable.

View 13 Replies

SQL Server :: Query To Return Conditional Counts Both Distinct And Non Distinct?

Sep 30, 2010

I have the following table structure:

[code]....

The following query returns the default recordset:

[code]....

View 4 Replies

Select Distinct And Include Non-distinct Columns?

Apr 20, 2010

I would like to select a distinct query based on three fields and display the rest of the fields. For example,

I have firstname, lastname, address, city, state and zip, but I only want to use the distinct on these fields first and last name. However when i use the distinct function I get a distinct on all the selected rows. I just want to distinct firstname and lastname and display the other fields. for example,

Mary Smith New York
Mary Smithy New York
Mary Smith Maine

I would like the result to be:

Mary Smith New York
Mary Smithy New York

I don't care about Mary Smith Maine, because i am only using the distinct for "Mary Smith" firstname and last name and showing the city.

View 15 Replies

C# - Populate DataTable With Records From Database?

Oct 8, 2010

This is my GET Method to get my data from my DataTable

Private Function GetData() As PagedDataSource
' Declarations
Dim dt As New DataTable
Dim dr As DataRow
Dim pg As New PagedDataSource

' Add some columns
dt.Columns.Add("Column1")
dt.Columns.Add("Column2")

' Add some test data
For i As Integer = 0 To 10
dr = dt.NewRow
dr("Column1") = i
dr("Column2") = "Some Text " & (i * 5)
dt.Rows.Add(dr)
Next

' Add a DataView from the DataTable to the PagedDataSource
pg.DataSource = dt.DefaultView

' Return the DataTable
Return pg
End Function

It returns the DataTable as "pg"

What changes must I make to this GET method to get the records from a table in my database?

C# examples will also do but would be great to see a reply with my code and then the changes....

View 1 Replies

Web Forms :: Append Records From One DataTable To Another

Apr 2, 2012

How to append a records from one data table to another data table.

In both the data table, I am having a similar columns.

View 1 Replies

DataSource Controls :: Fetch Top 10 Records From DataTable?

Jun 29, 2010

I have One DataTable Having 500 Records, want to Fetch Top 10 Record. how to do it

View 2 Replies

Add Records From DataTable To ArrayList Using AddRange Method?

Mar 25, 2011

i have a dataTable, which contains a column which has 100 rows, now i want to add those rows in ArrayList, but not with the Add Method, because i have to use for loop for adding records one by one, so i want to prefer addrange method of arraylist, so it is possible to add records in arraylist from DataTable using AddRange.

Below is the code which i am using.

Dim adapGetImages As New SqlDataAdapter("select distinct FileName from Files where Filename<>'' and (RIGHT(FileName,3) = 'gif' or RIGHT(FileName,3) = 'jpg' or RIGHT(FileName,3) = 'bmp') order by FileName", connection)
Dim dtGetImages As New DataTable()
adapGetImages.Fill(dtGetImages)
ArrayList1.AddRange(dtGetImages.Rows[0][0].ToString())

The last line is where i am stuck. as if i run this it will just add single row, and if i say dtGetImages.Rows.ToString() then this will just Add System.DataRow in Arraylist and not its content.

View 2 Replies

C# - SQL Server - Refreshing Cached DataTable With Only Records That Have Changed

Jan 20, 2010

I have a large DataTable cached in my web app that is the result of a complex query that returns a large data set. Whilst this data table is cached the query that runs to "refresh" this cache still takes a long time, largely due to the sheer amount of data being returned. In order to speed this up I am considering implementing a timestamp type approach to my tables in order to limit my query to only return rows which have changed.

I then intend to merge this smaller dataset with my cached datatable. Has anyone done anything similar to this, or is there anything out there that handles this already? I feel this could be a re-inventing the wheel situation if I dive straight in.

View 1 Replies

Web Forms :: Query DataTable To Get Records Between Start And End Dates

Apr 5, 2012

I have to filter the records from the data table based on the date.

I am having a column in data table called "cStartDate".

I will enter the begin and end date. I have to find out whethere the "cStartDate" is within the begin and end date i entered.

I am going to implement the filter logic in data table with out affecting the data base.

I need a Filter string for this.

View 1 Replies

Data Controls :: Fetch Top N Records From DataTable Or DataSet In Net Framework 2.0

May 7, 2015

Aspx code:

MembershipUser m_user = Membership.GetUser();
DataTable dt = new DataTable();
dt.Columns.Add("SenderUser");
dt.Columns.Add("RcvUser");
dt.Columns.Add("Message");
foreach (ListItem li in lst_Users.Items) {

[Code] ....

I am calling "Application object" from above aspx page into web service page as below:

[WebMethod(EnableSession = true)]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string WebMessage() {
List<string> list = new List<string>();
DataTable dt = ((DataTable)HttpContext.Current.Application["Message"]);

[Code] ....

I want to know that the approach im using in Web service page to fetch top 5 messages from Datatable is correct or not? How to do that without using LINQ as I am using framework 2.0 ...

View 1 Replies

Forms Data Controls :: How To Edit Records In GridView With Datasource Datatable

Jul 24, 2010

I am new to asp.net.I am buliding an online shopping application.Could anyone tell me the steps to edit records in gridview which have its datasource i.e. datatable.Means the shopping cart wil display its products.i want to do editing in gridview say quantity or product which automatically edit records(quantity) in datatable and then gridview wil again get bind to new edited datatable and able to show edited records say edited quantity of taht product.

View 4 Replies

DataSource Controls :: Does Dataset Store All Its Datatables' Records Into Memory If I Just Call One Datatable From It

Apr 2, 2010

Does dataset store all its datatables' records into server memory if I just call one datatable from it?Lets make an example, a dataset with three datatables - tbCompany, tbCompanyStaffs, tbSalesOrderwhere tbCompany is the parent of tbCompanyStaffs. tbSalesOrder is an independant table.Does dataset load all tbCompanyStaffs records into the server memory as well when a class retrive data from tbCompany?

View 3 Replies

SQL Server :: How To Get Distinct Column Name Which Are Having Distinct Values In The Column

Feb 4, 2011

I have one table(tableName is getDetails and having three column ID, Name, City)

View 6 Replies

Error "DataTable Is An Ambiguous Reference Between System.Data.DataTable And Microsoft.Office.Interop.Word.DataTable"

Jan 20, 2011

'DataTable' is an ambiguous reference between 'System.Data.DataTable' and 'Microsoft.Office.Interop.Word.DataTable'

View 3 Replies

Pass Datatable To The Mvc View Error / CS0246: The Type Or Namespace Name 'DataTable' Could Not Be Found

Sep 28, 2010

I was reading: [URL]

But I have give a compilation error:

CS0246: The type or namespace name 'DataTable' could not be found (are you missing a using directive or an assembly reference?

View 1 Replies

DataSource Controls :: How To Copy The Data From One Datatable To Another Datatable Based On The Schema

Jan 11, 2010

i have the dataset with one table.Table contains three column like 'Name','Location','Pin'.I would like to move the data from another table based on schema.

View 2 Replies

Forms Data Controls :: Set A Column In A DataTable To Be A Primary Key For An Existing Datatable

Apr 2, 2010

If I am passed a datatable and I cant change the column structure..is there anyway to set an existing column to a Primary key so I can easily Find() the row I am looking for?

View 1 Replies

ADO.NET :: How To Select The Distinct

Feb 9, 2011

Having some troubles selecting distinct rows.

[Code]....

This is not giving me the wanted results.

Two models:

[code]....

Each ContentVersion is linked to Content through the ContentID.

I want to select all "Content" where UserID = X, then for each selected "Content" I want the latest "ContentVersion".

The return type should be of type <IQueryable>ContentVersion.

View 21 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved