.net - Get Duplicates For Two Columns With LINQ

Sep 23, 2011

LINQ drives me crazy. Why does following query not return the duplicates, whereas it works with only one identifier? Where is my error?

[Code]...

View 1 Replies


ADVERTISEMENT

Removing Duplicates Using 2 Columns In Dgview?

Jun 13, 2012

My dgview has some records. But I wanna eliminate the duplicate rows from dgview if the first column and the last column values are same for the rows.in the below image rl1,rl2,rl4 are repeated but the values in ch2 and ch3 are different but still the value in ch4 are same for rl1,rl2,rl4.

so i wanna keep the first instance of rl1,rl2,rl4 displayed at the first time and rest should be removed.

But look rl2 it is case sensitive as the first instance is displayed as rl2 and the second as RL2. But still ignore the case sensitive and should display the result as in dgview2. I am populating from a csv file and it must work for many records.

View 1 Replies

Compare The Two Data Table Columns And Find Duplicates?

Feb 15, 2012

i want to compare the two data table columns and find duplicates for example

dataTable1
autoid ponbr polinenbr quantity
1 0001 10 5
2 0002 12 6

[code]....

in the above two dataTable i would like to compare the ponbr and polinenbr column and find the duplicates and get the autoid..

View 2 Replies

Office Automation :: Columns As Objects Part - Removing Duplicates

Nov 28, 2009

I am Tring to Make this work but I do not understand the Colunms as objects Part. Here is what I got

[Code]...

View 3 Replies

Remove Duplicates From Dropdownlist With LINQ?

Mar 1, 2012

I have a dropdownlist with some duplicate items on it. I intended to remove them by using LINQ, but do not know how to do it.

View 1 Replies

LINQ VB How To Check For Duplicates In A List Of Objects

Oct 11, 2011

I have a list of objects, each with 2 relevant properties: "ID" and "Name". Lets call the list "lstOutcomes".I need to check the list for duplicates (meaning object1.ID = object2.ID, etc.) and set a flag (valid = false, or something) if there is at least one duplicate. Also, it would be nice to send a message to the user mentioning the "Name" of the object, when it fails.I am sure I will need to use the Group By operator to do this, but I am not used to doing that in LINQ, and the examples out there are just not helping me. This article seems to be close to what i need, but not quite and it's in C#.

Here is a starting stab at it...
Dim duplist = _
(From o As objectType In lstOutcomes _

[code]......
help?

View 4 Replies

C# - Search Two Columns In LINQ To SQL?

Apr 15, 2011

I am trying to make a simple search method using sql to linq in visual studio. In my database, i have the fields "Firstname" and "Lastname", and my search string is "name". How can i make a simple linq query which searches both fields?

in plain SQL i would do something like this: "SELECT (Firstname + Lastname) as 'Fullname' FROM table WHERE Fullname LIKE '%searchstring%'

View 3 Replies

Use LINQ To Total Columns?

Dec 12, 2011

I'm trying to get LINQ SQL to grab and total this data, I'm having a heck of a time trying to do it too.

Here is my code, that doesn't error out, but it doesnt total the data.[code]....

View 1 Replies

Linq - Group By Multiple Columns?

Dec 6, 2011

I have a list of attachments that I need to group by clientCLID and EmailAddress. From this grouped list I only need a list of clientCLIDs. After fiddling for a while I've managed to get it to work as follows:

[Code]...

View 1 Replies

Sum Up Specific Columns In Gridview Using Linq?

Mar 19, 2012

how to sum upan specific columns in gridview using linq? I can't find anything in Google regarding this topic.

I tried this but not exactly what I want to be the output.

Dim total = Aggregate rowItems In Gridview1.Rows _
Into Sum(Cdbl(rowItems("AMOUNT")))

View 3 Replies

Add Custom Columns To A Table That LINQ To SQL Can Translate To SQL

Aug 26, 2009

I have a table that contains procedure codes among other data (let's call it "MyData"). I have another table that contains valid procedure codes, their descriptions, and the dates on which those codes are valid. Every time I want to report on MyData and include the procedure description, I have to do a lookup similar to this:

From m in dc.MyDatas _
Join p in dc.Procedures On m.proc_code Equals p.proc_code _
Where p.start_date <= m.event_date _

[Code]....

Is there a way to turn a complex lookup (i.e. a non-trivial join) like this into something SQL can recognize so that I can define it in one place and just reference the description as if it were a field in MyData? So far the only thing I can think of is to create a SQL view on MyData that does the linking and bring that into my data context, but I'd like to try to avoid that.

View 2 Replies

Asp.net - Loop Through Controls And Change LINQ Columns?

Jun 29, 2010

I have the following code:

Dim i As Integer
For i = 1 To 20
Dim captionTextBox As TextBox = DirectCast(Me.FindControl("news_Image" +

[Code].....

Where the comment is in the code above, I need to insert the value of the textbox (text) into Linq columns. For example: articleToUpdate.news_Image1Caption, news_Image2Caption, but I need to change the number after news_ to the value of i in the for loop.

View 1 Replies

How To Group Distinct Columns In A Linq Query

Nov 4, 2010

The following data is created by joining two sql tables together:I would like to group together distinct rows of DateStamp/UserName/ StudentName/ InstructorName/TableName/PrimaryKey (I'll call this 'group records') and then group under these ColumnName/PreviousValue/NewValue (I'll call this 'subgroup records')The end result would be that I could iterate through the 'group records' - there would be 5. In each 'group record', I could then iterate through the 'subgroup records'. The 5 groups would contain 3, 2, 5, 2 and 1 subgroup records respectively.What would be the syntax to create a query to do this? Ideally this would be in a vb.net linq syntax.

View 1 Replies

LINQ To SQL Grouping Multiple Columns With A Distinct Row

Aug 9, 2010

I have the following table structure. I want to select distinct CustomerId and CustomerName, TotalCost.[code]

View 2 Replies

Update Columns In Datatable Using Linq Without Condition?

Jun 22, 2011

How to update columns in datatable using linq without conditions. I have an idea that I'm just gonna loop all the data in the datatable but don't know what comes in LINQ.

View 5 Replies

.net - Proper Syntax For LINQ Query Selecting Only Certain Columns?

Sep 13, 2011

What is the proper syntax for this:

Dim qry As <??> = From f In dirInfo.GetFiles("*.QBW") Select File = f.FullName, Include = True
Dim dt As DataTable = qry.CopyToDataTable()

I tried as "IEnumerable(Of DataRow)" but that didn't work. At runtime it said:

Unable to cast object of type
'WhereSelectArrayIterator2[System.IO.FileInfo,VB$AnonymousType_02[System.String,System.Boolean]]'
to type
'System.Collections.Generic.IEnumerable`1[System.Data.DataRow]'.

View 5 Replies

C# - LINQ To SQL Join 3 Tables And Select Multiple Columns And Also Using Sum

Aug 19, 2010

I have three tables Student, TimeSheet and TimeRecord.

Talbe columns:
Student : StudentId, FirstName,
LastName
TimeSheet: TimeSheetId,StudentId, IsActive

[Code].....

View 4 Replies

Linq - Order By Multiple Columns Using Lambda Expressions

Nov 16, 2009

I'm still trying to get my head around the whole "Lambda Expressions" thing.

Can anyone here give me an example ordering by multiple columns using VB.Net and Linq-to-SQL using a lambda expression?

Here is my existing code, which returns an ordered list using a single-column to order the results:

Return _dbContext.WebCategories.OrderBy(Function(c As WebCategory) c.DisplayOrder).ToList

Note: The WebCategory object has a child WebPage object (based on a foreign key). I'd like to order by WebPage.DisplayOrder first, then by WebCategory.DisplayOrder.

I tried chaining the order bys, like below, and though it compiled and ran, it didn't seem to return the data in the order I wanted.

Return _dbContext.WebCategories.OrderBy(Function(c As WebCategory) c.DisplayOrder).OrderBy(Function(c As WebCategory) c.WebPage.DisplayOrder).ToList

View 2 Replies

LINQ Query - Join Tables On Nullable Columns

Apr 17, 2011

How to JOIN tables on nullable columns? I have following LINQ-query, RMA.fiCharge can be NULL:
Dim query = From charge In Services.dsERP.ERP_Charge _
Join rma In Services.dsRMA.RMA _
On charge.idCharge Equals rma.fiCharge _
Where rma.IMEI = imei
Select charge.idCharge

I get a "Conversion from type 'DBNull' to type 'Integer' is not valid" in query.ToArray():
Dim filter = _
String.Format(Services.dsERP.ERP_Charge.idChargeColumn.ColumnName & " IN({0})", String.Join(",", query.ToArray))
So I could append a WHERE RMA.fiCharge IS NOT NULL in the query. But how to do that in LINQ or is there another option?

The problem was that the DataSet does not support Nullable-Types but generates an InvalidCastException if you query any NULL-Values on an integer-column. The modified LINQ-query from dahlbyk works with little modification. The DataSet generates a boolean-property for every column with AllowDbNull=True, in this case IsfiChargeNull.

Dim query = From charge In Services.dsERP.ERP_Charge _
Join rma In (From rma In Services.dsRMA.RMA _
Where Not rma.IsfiChargeNull
Select rma)
On charge.idCharge Equals rma.fiCharge _
Where rma.IMEI = imei
Select charge.idCharge

View 2 Replies

Linq To Datarow, Select Multiple Columns As Distinct?

Apr 16, 2010

basically i'm trying to reproduce the following mssql query as LINQ

SELECT DISTINCT [TABLENAME], [COLUMNNAME] FROM [DATATABLE]

the closest i've got is

Dim query = (From row As DataRow In ds.Tables("DATATABLE").Rows _
Select row("COLUMNNAME") ,row("TABLENAME").Distinct

when i do the above i get the error

Range variable name can be inferred only from a simple or qualified name with no arguments.

i was sort of expecting it to return a collection that i could then iterate through and perform actions for each entry. maybe a datarow collection?

As a complete LINQ newb, i'm not sure what i'm missing.
i've tried variations on

Select new with { row("COLUMNNAME") ,row("TABLENAME")}

and get:

Anonymous type member name can be inferred only from a simple or qualified name with no arguments.

to get around this i've tried

Dim query = From r In ds.Tables("DATATABLE").AsEnumerable _
Select New String(1) {r("TABLENAME"), r("COLUMNNAME")} Distinct

however it doesn't seem to be doing the distinct thing properly.

View 3 Replies

Linq To Sql, Aggregate Columns ,group By Date Into Listview?

Aug 3, 2011

also i have a table called Orders with several columns, they contain information about the order and store the ID of the Customer they belong to.Question is: how can i query that table with (preferably) linq (the datacontext is from LinqToSql) to return the following dataI want to search for any entry with the matching CustomerID which took place, group them by Year, Sum the Totals respectively and add them to the listview?I now i could use lamda expressions and aggregate, its just not clear how (option infer on,db is a datacontext object,CustomerID is an int32 variable):

Dim Orders = (From order In db.Orders Where order.CustomerID = CustomerID).GroupBy(Function(p) p.Date.Year).GetEnumerator
I reckon i'd have to create an anonymous type like the following:

[code].....

View 1 Replies

LINQ VB To Read Many Columns (or Fields) In One Row Record Data?

Oct 1, 2010

The LINQ VB code below is to read the first record data for database table
ProductTable that has 3 colounms (or 3 fields):

TableCol1, TableCol2, TableCol3. The reading data is stored at variable
MyArrayFirstRow.
'-------start LINQ VB code in Visual Studio Web Developer 2008-------'
Dim MyArrayFirstRow

[Code].....

View 12 Replies

VS 2010 LINQ To SQL - Columns Returning In Alphabetical Order?

Sep 9, 2010

I am using LINQ queries inside a WCF service to return data to a Silverlight frontend. Problem is the columns being returned using LINQ are in alphabetical order and I want them the way they are ordered in the database instead. Does anyone know how to stop the alphabetical ordering of column names?

View 4 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# - Joint Query In Linq To SQL To Select All Records Even There Are Some Null In The Columns Of Foreign Keys?

Feb 2, 2011

I'd like to take all suggestion either in C# or VB.NET.I have a DB diagram like the image below. I also include the database script here [URL]In the Students table, CountryId and RoomId column are allowed null. Because some records do not have info about room and country yet.Also, some students do not have essays.I'm doing a joint query with all tables. I want to select all students to project the result like this:Wanted query result.

Here's my current query that gives the result like the image below:

Dim db As New DBDataContext
Dim query = From st In db.Students _
Join c In db.Countries On c.Id Equals st.Id _
Join r In db.Rooms On r.Id Equals st.RoomId _

[code].....

current query result I got only one result back because I have (2) William NoMan record in every table. But I don't get anything about others, like (3) Sync Master who has everything but RoomId.What do I need to modify the query above so it will give me all students like in the wanted query image above?

View 2 Replies

C# - LINQ To SQL Join Two Tables To Select Parent Table Twice Based On Two Different Columns From Child Table?

Aug 23, 2010

I have two tables Employees and CafeLogs. Some employees can be cashiers and also customers at the Cafe shop.

Table structures:

Employees: EmployeeId(PK) , FirstName, LastName
CafeLogs: LogId (PK), CashierId, EmployeeId, Value, => CashierId and EmployeeId are the data from column EmployeeId of Empoyee table

Table relationship:

Employees 1:N CafeLogs (CashierId (FK))

[code]....

Right now I know how to select only LogId, Employee's name, and , Value, not with Cashier name yet.

Dim query = From log In db.CafeLogs _
Join emp In db.Employees On emp.EmployeeId Equals log.EmployeeId _
Select log.LogId, emp.FirsName, emp.LastName, log.Value

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

DataGridView, Set Up Columns, Populate Data Table, Bind, But Not Using Columns Created In Code?

Oct 26, 2011

I'm using VB.net 2005. I have working programs that I populate DataGridViews with something like the following:

[Code]...

View 6 Replies

Add/subtract/divide/multiply Certain Columns And Place The Information Into Other Columns?

Nov 30, 2010

My goal is to connect to my database either manually or using an sqladapater, and get information from two of my databases on sql server 2005. Then I want to take this information and on run-time begin to add/subtract/divide/multiply certain columns and place the information into other columns. I can do this in queries, however, I want to do it on run-time what is the best way to achieve this.I had some of this working, but I just want to start fresh and see how you would go about doing this.

[Code]...

View 2 Replies

.net - Aggregate The Columns To Group On The Period And Sum The Count Columns?

Jun 29, 2011

I have the below Linq query that is returning the data but I need to aggregate the columns to group on the Period and Sum the Count columns. How do I go about doing this?

LINQ
from t In tblTimes
join h In tblEngineeringDashboard_CADMachinesCounts on t.ID Equals h.TimeID
Order By t.Period

[code].....

View 1 Replies







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