LINQ To DataTable, Finding Duplicate Rows?

Jul 5, 2011

Using the following DataTable:

Dim d As New DataTable()
d.Columns.Add("Product", GetType(System.String))
d.Columns.Add("Value", GetType(System.Double))

[code]....

I'm trying to use LINQ to identify if there are more than one of any type of product. In SQL, this would work something like:

SELECT Product FROM SOME_TABLE HAVING COUNT(*) > 1

I can't for the life of me work out how to do this in LINQ. I was following someone who did something like this:

Dim q = From row In d.AsEnumerable()
Group row By New { column1 = row("Product"), column2 = row("Value") }
Into grp

[code]....

But I get an error when I try to actually use 'q'. how I can make this work?

View 3 Replies


ADVERTISEMENT

VS 2008 Finding Duplicate Rows In A DataGridView?

Aug 26, 2010

If I have an unbound DGV with hundreds or thousands of rows what is the easiest way to find any or all duplicate rows? ie. where the data in all the columns is the same in 2 or more rows.

View 4 Replies

Removing Duplicate Rows In A Textfile Then Add To Datatable?

Aug 16, 2010

I am reading a textfile and extracting information from each line. For example string1 and string2. I am then writing these string to a datatable.

However, sometimes there will be repeats in string1 and string2.

If there are repeated lines I would like to be able to delete the repeating line and add a counter to find the total number of repeating lines.

so if a string repeates 3 times I would like there to be a column with a 3 displayed next to the line in my datatable.

View 4 Replies

Compare Two Datatable And Delete Some Rows By Linq?

Nov 18, 2010

there is two datatable at some datasetsone of them is tbl1 and fileds is (pcode,points) other table is tbl2 and fields is (pcode,stoped)"pcode" is equal at two tables

View 6 Replies

Select Distinct Rows From Datatable In Linq

Jul 14, 2010

I am trying to get distinct rows based on multiple columns (attribute1_name, attribute2_name) and get datarows from datatable using Linq-to-Dataset.[code]How to do thin Linq-to-dataset?

View 3 Replies

VS 2010 LINQ On A DataTable - Are Rows Returned As Reference

Feb 6, 2011

When I query a DataTable using LINQ, are the rows returned as references? Either way, is it possible to control this behaviour, so that rows are either returned as references or as new rows?My guess is that all objects are returned as references by default, since that seems to be the normal behaviour in most programming languages.

View 2 Replies

Asp.net - Select Distinct Rows From A Datatable With Criteria Involving Multiple Columns Using LINQ

Mar 9, 2012

I have a datatable as shown in the figure. Let me explain my required based on this image. I have 7 rows of data. The rows 1 and 2 contains columns till UnitSqcNo same. I want only row 3 among the two. In general I want select all the rows with distinct model, unittype, unit and rest with greater CompId. ie the table should look like

View 1 Replies

C# - Get Distinct Rows From Datatable Using Linq (distinct With Mulitiple Columns)

Jul 13, 2010

I am trying to distinct on multiple columns and get datarows from datatable. but getting error.

Dim query As IEnumerable(Of DataRow) =
(From row As DataRow In SourceTable.AsEnumerable() _
Select row.Field(Of String)("ColumnName1"),

[Code]....

I want another datatable with distinct row based on given columns from SourceTable.

View 3 Replies

VS 2010 : Combine Similar Rows In A Datatable (the Rows Only Differ By One Column)?

May 8, 2012

I have three sub tables that I want to process. For each I want to combine the rows, as they are only different by contents in the second column(I want to do the same to the fourth column, later):

'Sub table 1
xx|C201 |02300877 |Samsung |....
xx|C201 |02300877 |Toshiba |....
xx|C213 |02300877 |Samsung

[code]....

p.s. For the fourth column, Manufacturer information , I want to do the same and I'd probably get something like this for the final table:

xx| C201,C213,C606,C619 |02300877 | Samsung
xx| C201,C213,C606,C619 |02300877 | Toshiba
xx| C303, C305,C712 |02301163
xx| C207, C209, C708 |02301165

View 5 Replies

Add Rows To A DataTable Without Losing The Previous Rows?

Apr 14, 2012

Dim _tableBackLogs As System.Data.DataTable
Do While i - 2 > 0
_tableBackLogs = Global.DataAccess.GetDataTable("SELECT SubjectID,SubjectName,Grade FROM SubjectPI WHERE RegNo='" & CInt(HttpContext.Current.Session("userName")) & "' AND Status='Fail' AND Semester='" & i - 2 & "'")
i = i - 2

Doing this replaces the previous data in the DataTable. I want to retain the previous data i.e i want the new rows to be added to the DataTable w/o replacing the previous rows.

View 2 Replies

Counting The Duplicate Rows In Datagridview?

Feb 16, 2012

I have a datagridview with rows and 2 columns the first for staffname the second for the price the first column name is "staff" the second is "price" I want code count's how many time the row have been repeated to count the item price

View 8 Replies

Datagridview Remove Duplicate Rows

Apr 8, 2010

My browser application has an option to display all the "href" elements of a web page in a datagridview.

I use the code below to populate the datagridview.[code]...

View 10 Replies

[2008] Duplicate Rows In DataDridView?

May 26, 2008

I am looping through a file and I am populating a datagridview with values. I have this part done, and it works just fine. My problem comes in when I try to remove duplicate rows from the DataGridView. I would like the code to increment a cell if a duplicate row is found and then remove the duplicate cell. For instance if the program comes across 2 instances of "duplicated value" in the DateGridView, I would like the second instance to be removed and then a value of 1 added to the first instances row, 4th column. I understand most of it, but I just can't get the darn loop(s) working correctly. Iguess my theory is to compare the first row to the last row. if there is a duplicate, then remove the duplicate and add "1".Then I should move onto the next item from the top. This would loop until all items have been checked. I have been messing with this for a while now and I just keeps getting worse.

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim col, row, MaxCount, x, y As Integer

[code]....

View 3 Replies

VS 2010 ListView - How To Avoid Duplicate Rows

Sep 22, 2009

I am populating the list view using mysql and i dont know how to avoid duplicate rows.
Private Sub Btnrefresh_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btnrefresh.Click
Using connection As New MySqlConnection(";")
Using command As New MySqlCommand("SELECT Distinct name, type, uploaded, uploader, location FROM programs", connection)
connection.Open()
[Code] .....

View 5 Replies

Delete Subsequent Duplicate Rows In A Text File

Jun 30, 2010

I'm going nuts with this. Obviously I cannot open the reader ard writer on the same file simultaneously.

[Code]...

View 1 Replies

VS 2008 Duplicate Date And Times In A Datatable?

Jan 16, 2011

Having problems with a datatable which consists of multiple datalogger information. Within the datetime field there are as the name suggests listed date and times entry i.e. 12/01/11 22:56:56 ect ect.

Problem is i am graphing this and when ms chart reads the duplicate entries as a series. It doesnt like it and comes up with a slightly odd interpretation. I need to get the duplicate entries out to establish a single time series.

I was proposing to clone the original datatable and run a loop to remove the duplicates. I have been trying to do this for days and have played with a whole load of examples, without success. Can anyone point me in the right direction on this.

View 1 Replies

.net - Linq OrderBy On Duplicate Values?

Oct 20, 2011

m_ListOfsAllFields.OrderBy(Function(x) x.DisplayOrder)

here I have DisplayOrder = 0 for 2 fields, so orderby is messing up and not ordering properly. How can I use orderby to order this collection?

View 2 Replies

Bind Combobox To Datatable And Object Property Causing Duplicate Bindings

Aug 19, 2011

I'm trying to populate the list of a combobox by binding it to a datatable. Also, I want the selected value of the combobox to be bound to an object property so that when the selected value changes, it's automatically updating the object. However it's causing an error at runtime: "This causes two bindings in the collection to bind to the same property.

Parameter name: binding" I thought binding the dropdown list to a datatable and the selected value to an object were different properties but obviously I'm not getting it right.

Code:

Private Sub PopulateSiteSelect()
With Me.PlanSiteSelect
If _Plan.PlanID <> Nothing And _User.UserID <> Nothing And _Plan.Category <> Nothing Then

[Code]....

View 3 Replies

Doesn't The Union Function In LINQ Remove Duplicate Entries?

Aug 9, 2009

I'm using VB .NET and I know that Union normally works ByRef but in VB, Strings are generally processed as if they were primitive datatypes.Consequently, here's the problem:

Sub Main()
Dim firstFile, secondFile As String(), resultingFile As New StringBuilder
firstFile = My.Computer.FileSystem.ReadAllText(My.Computer.FileSystem.SpecialDirectories.Desktop & "1.txt").Split(vbNewLine)
secondFile = My.Computer.FileSystem.ReadAllText(My.Computer.FileSystem.SpecialDirectories.Desktop & "2.txt").Split(vbNewLine)

[Code]...

View 2 Replies

LINQ - Create SubList And Skip Items With Duplicate Property Values

Apr 4, 2012

The problem is: I have a list of objects, with some containing the same PlanId property value. I want to only grab the first occurrence of those and ignore the next object with that PlanId. The root problem is a View in the database, but it's tied in everywhere and I don't know if changing it will break a ton of stuff nearing a deadline.

So, if I have a list of PlanObjects like such.
Plan1.PlanId = 1
Plan2.PlanId = 1
Plan3.PlanId = 2
Plan4.PlanId = 3
Plan5.PlanId = 4
Plan6.PlanId = 4

I want to take a sub-list from that with LINQ (italics mean an item is not included)
Plan1.PlanId = 1
Plan2.PlanId = 1
Plan3.PlanId = 2
Plan4.PlanId = 3
Plan5.PlanId = 4
Plan6.PlanId = 4

For my needs, it doesn't matter which one is taken first. The Id is used to update a datsbase record.

View 1 Replies

DGV Rows To Datatable?

May 29, 2009

I have a DGV that has a datasource to load the rows I need for display.

Now, I need to save the selected rows to a DataTable.

binding the DGV. I created the DataTable in my DataSet dsProfiles1 and created a BindingSource - bsDataTableDGV

DataTable:

ClientID Int32 not null PK
ClientName String not null
ProgramNo Int32 Not Null

[Code].....

View 9 Replies

How To Add New Rows Into DataTable

Feb 15, 2012

I have a form with a textbox and a add button. User can write a name down on the textbox and click add button. it will save in a datatable with auto ID. After that, the textbox is cleared and the user can write another name on the text box and click the button. This should add to the existing datatable on memory with existing ID + 1. Show on the gridview. (this is just for display purpose to confirm it works)

I have a datatable like this.
Button1.click() event
Dim name = txtname.Text
Dim dt As New DataTable
dt.Columns.Add("ID", GetType(Integer))
[Code] .....

At the moment I have sometime like the code above. in the real program, it is not just name and it is not just one datatable so i just mock up some code. And this code for aspx.
<asp:TextBox ID="txtname" runat="server">
</asp:TextBox><asp:Button ID="Button1" runat="server" Text="Button" />
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>

View 1 Replies

.net - Flip Two Rows Of A Datatable?

Jan 14, 2011

I Have a datatable in .net. I need to flip the location of two of them. For example, a datatable that the select statement had an order by priority clause. The user wants to up the priority of a single row by selecting it and clicking increase priority, how do i move a row up (AKA flip two rows)

View 2 Replies

Add Rows To A Datatable With Parallel.for?

Jul 13, 2010

I have this sub :

Private Sub error_out(ByVal line As Integer, ByVal err_col As Integer, ByVal err_msg As String)
Dim ln = t_erori.Rows.Add

[Code]....

I suspect this is because it's trying to add the same row twice.
How can i make this work ? Or what else method could I use to do this ?

I need this datatable because my app is writing some results in there, but any other method to store the results that works with parallel.for would be ok.

View 2 Replies

Asp.net - Merge Rows In Datatable Which Had Same Value (VB)?

May 13, 2012

I have one datatable tempDT with value :

[Code]...

The problem is I want merge duplicate serial_no into one row which the value of testong adding to new column. I have tried many ways, but I can't find the solution. Here is my code behind :

[Code]...

View 2 Replies

Datatable Compare Rows?

Apr 17, 2009

I have a datatable object, which is populated from a webservice.Apparently, the web service just throws everything (data) back to me. The data which gets in my datatable looks like this:

Dept Code Value
Science ABC 5
Science ABC 6

[code].....

View 1 Replies

Delete All Rows In Datatable?

Apr 8, 2010

At the moment I use this code but I have 591 rows to delete and it takes forever to loop and delete each row on an individual basis

[Code]...

View 7 Replies

Delete Rows From Datatable?

Feb 10, 2012

i need to delete some rows from datatable

i don't know the indexes i have 2 columns to idendify the rows to delete

how to achive this in easy way

i don't want to delete inside loop wat will happen if i have 2 million rows? tats why i don't want to delete indendify the rows and delete in loop

View 8 Replies

How To Delete Rows From DataTable

Mar 20, 2009

I have a Datatable in my code in vb.net. I need to delete rows from the datatable. The name of my Datatable is "temptable".in my row deleting event of a Gridview control. I wrote code as follows:

In the Row_Deleting event of Gridview:
temptable.Rows.Remove(Gridview1.Datakeys(e.RowIndex).value)

But,it shows an error as follows:
"Cannot cast System.Int32 to System.Data.Datarow".

View 2 Replies

Loop Through The Rows Of A Particular DataTable?

Jan 9, 2009

IDE : VS 2008,Platform : .NET 3.5,Here is my DataTable columns :ID Note DetailI want to write sth like this :

View 8 Replies







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