Select Two Datacolumns From A Datarow In Linq ?

Aug 23, 2010

Dim orders = From tt In testTable _
Order By tt.Item("OrderNumber") _
Select tt.Item("OrderNumber"), tt.Item("OrderId")

This is breaking. Is there a way to do this? I would have thought it was easy enough. Obviously, I thought wrong....

View 1 Replies


ADVERTISEMENT

Loop DataColumns In DataRow

Apr 17, 2012

I am converting data table content to string, Say the dataset has 12 rows and 8 column.
At the end, the Dict contain 12 rows or 96 columns. what's wrong with my code below, how do I reset the row?

Dim ds As DataSet = ClsDB.GetDataSet(sql)

If Not ds Is Nothing AndAlso ds.Tables.Count > 0 Then
Dim row As New List(Of KeyValuePair(Of String, String))

[CODE]...

View 1 Replies

Select DataRow With Latest Date Using LINQ/

Jul 23, 2012

I have a datatable where there are 3 columns

ID | Name | Date
and i have 4 columns
1 | ABC | 20/07/2012

[code].....

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 : Find Item In DataRow[]?

Sep 28, 2011

gefundeneID = drTerminal.AsEnumerable().Single(Function(s) s("TerminalID") = RandomID)Have an array of DataRow and want to look if the RandomID is in one of the rows.What's wrong with this code?

View 2 Replies

Make Datacolumns.expression?

Oct 28, 2009

Dim col As DataColumn = dt.Columns(index)
' Remove (and automatically empty) the column object from the table
dt.Columns.Remove(col)

[code].....

View 13 Replies

Reorganize Datacolumns At Runtime?

Sep 1, 2010

is there any way to change the order of the datacolumns in a datatable at runtime.

View 2 Replies

Merge Multiple Datacolumns In A Datatable?

Feb 2, 2012

I am trying to merge multiple datacolumns in a datatable. Eg. The address data is stored in a different columns such as, Housename, street, city and postcode. I want to merge those datacolumns in to one and put it into one datacolumn as "Address".

View 1 Replies

Asp.net - LINQ To SQL - Select SUM With A WHERE?

Aug 17, 2009

I'm having trouble getting a Linq to Sql query to work. Basically, I want the sum of a column in a table for only rows matching a certain condition. A simplified version is this:

Orders = order that contains products
OrderProducts = relational table containing products that are in an order
Products = table containing information about products

I can get the total sum of the qty of products like this:

Dim totalQty = requests.Sum(Function(p) p.OrderProducts.Sum(Function(q) CType(q.ProductQty, Nullable(Of Integer))))

(Requests is a IQueryable of Orders)But I also need to get the sum of qty where the actual product meets a certain condition. Something like...

Dim totalQty = requests.Sum(Function(p) p.OrderProducts.Sum(Function(q) CType(q.ProductQty, Nullable(Of Integer))))... WHERE p.OrderProducts.Product.ProductAttribute = true

How would I go about getting that query with the additional where clause to only get the sum of the qtys where the productAttribute = true ?

View 1 Replies

Linq To SQL Sub Select?

Oct 12, 2009

I have the following query which groups some records and then filters where the count of the grouped records is 1.

I'd like to take the returned result and perform another query to retrieve the entire record from the JobcodesWorkingRollup table where the ParentNode column equals the result of this query:

Dim query = From r In context.GetTable(Of JobcodesWorkingRollup)() _
Group r By r.ParentNode Into g = Group _
Where g.Count = 1 _
Select New With {.cnt = g.Count, .nm = g.FirstOrDefault.ParentNode}

View 1 Replies

Asp.net - Linq Select Compound From

Apr 16, 2009

I'm experimenting with linq compount selects. I find the following query not to return any element:

Dim q = From s In d.GetChildRows("DossierSinistri") _
From i In s.GetChildRows("DossierIncarichi") _
Select s

[Code].....

View 2 Replies

Asp.net Mvc - Why Can't Get Anything Back When Use Linq To Sql Select

Feb 3, 2011

Why can't I get any values back when I use Linq to Sql? BHS_TimeSheet is my database table in which have some records. Model.TimeSheet is a class I create in the model. Private db As DataFactoryDataContext

[Code]...

View 1 Replies

C# - Linq Ambiguity On Where And Select

Nov 15, 2011

Today I ran into an issue with LINQ to objects (not SQL) that popped up due to a typo. I had a .Select one place and a .Where in another place. I was expecting same result but they are showing different numbers. Assume somelist has 10 elements with all elements having qty = 0

[Code]...

View 4 Replies

LINQ Select In .NET And C# Differences?

Mar 16, 2011

When using VB.NET I can do the following:

Public Function GetUser(ByVal ID as Integer) As User
Dim dc As New YesEntities()
Return (From u in dc.Users Where u.ID = ID).Single()
End Function

And on my .aspx/.vbhtml page I can access the user's department name like this:

Dim DepartmentName as String = new User().GetUser(12).Department.Name

[Code]...

View 1 Replies

Select Controls Using LINQ?

Jul 25, 2010

i try to select controls using LINQ but it show error

here is the code:

Dim testcontrol As VariantType
testcontrol = From cControl As Control In Me.Controls.OfType(PictureBox) Select cControl Order By Name Ascending

[Code].....

View 2 Replies

[2008] Using Select With Linq

Jan 9, 2009

I have seen different examples in Linq and one used Select and another didnt but both return the same results. Is there a reason why we should use Select ?

[Code]...

View 1 Replies

.net - Linq To Object - Select Distinct

Mar 18, 2010

I can't quite figure out why this Linq Statement isn't working as i would expect:

[Code]....

I would assume that this would create a new collection of anonymous types, that would be distinct. Instead it creates a collection the size of the "ThisParentCollection" with duplicate "MyAnonymousType" in it (duplicate id's).

View 1 Replies

C# - Linq Select Certain Properties Into Another Object?

May 28, 2009

So say I have a collection of Bloops

Class Bloop
Public FirstName
Public LastName

[Code]....

Is it possible using Linq to select the FirstName and LastName out of all the Bloops in the collection of Bloops and return a collection of Razzies? Or am i limited to a For-Loop to do my work?

To clear up any confusion, either VB or C# will do. Also this will probably lead to me asking the question of (What about using a "Where" clause).

View 4 Replies

C# - Select` And `sub` Have Brackets Around Them In VB Linq Expressions?

Jul 12, 2011

I converted the following query from C#:

src.Select((c, i) => src.Substring(i)).Count(sub => sub.StartsWith(target))

To the VB.NET query:

src.[Select](Function(c, i) src.Substring(i)).Count(Function([sub]) [sub].StartsWith(target))

Using Developer Fusion. I was just wondering why the VB.NET version has [] throughout.

View 3 Replies

LINQ / Select Distinct From Dataset?

Aug 20, 2010

I have a single columned datatable inside a single tabled dataset.I just want to convert this dataset to distinct rows. Here is my code, it gives compile error '.' expected.

Dim query = _
From email In ds.Tables(0) _
Select email.Field<string>("Email").Distinct()

EDIT: I changed to (Of String) and it works... BUT NOW 'query' is an ienumerable collection of characters... not a datatable... so how do I convert back easily without manually doing a loop?

View 1 Replies

Linq To SQL Query To Select Maximum Value

Jun 21, 2010

Linq to SQL query to Select the maximum "MeanWindSpeed" value? The database name is "WeatherArchives" The TableName is "TblValues" The Column is "MeanWindSpeed" And Also, I would like to have a query to get me the Max "MeanWindSpeed" in each year,

View 1 Replies

Select Distinct In Linq Query?

Jan 4, 2012

I've a collection with the data like this.[code]...

how can select the distinct data using linq?

View 2 Replies

Select More Than One Column In A Linq Query?

Nov 2, 2009

Dim MyQuery = From c In xdoc.Descendants() _
Where c.Attribute(OriginY) IsNot Nothing _
Order By Val(c.Attribute(OriginY).Value), Val(c.Attribute(OriginX).Value) _
Select c.Attribute(UniStr)

Right above you can see my First! linq attempt! And here comes my first question.

How can i select more than one column in a linq query in vb.net?

For example... Select c.Attribute(UniStr) AND c.Attribute(OriginY)

View 1 Replies

Select Only Date Value No Time In LINQ To SQL?

May 17, 2009

I need to have a query which list all the user according to the date value in the database. Problems is this, in the database the date format is 5/5/2009 4:30:12 but I want to compare with 5/5/2009. I think the value of the based date is 5/5/2009 12:00:00 and that's why I couldn't query it.

The query is something like

dim db = new databcontext
dim user = from u in db.datacontext where u.signUpTime = 5/5/2009 select u.

View 1 Replies

Use If Statement During Select From Linq To Datasets?

Dec 14, 2009

I have this LINQ statement [code]...

Is there any way that I can use if/iif within select ?

View 1 Replies

Use Linq For Select Distinct Values?

Mar 28, 2012

I'm pretty new in Linq and the first problem I've is to select the Distinct values from a ObservableCollection( Of T)

I've tried with[code]...

View 2 Replies

.net - Reset Index In LINQ Select Clause?

Mar 13, 2012

My LINQ query:

Dim groupedData = (From p In pData _
Group By p.TruncParam Into Group) _
.SelectMany(Function(g) g.Group) _
.Select(Function(d, idx) New With { _

[Code]...

When the TruncParam changes, I would like the index (idx) in the Select clause to reset to 1. So, in the list above, the Index should be SOLUB0001, SOLUB0002, INSOL0001, INSOL0002...CLRES0001, SUMCA0001, SUME0001.

How should I alter the LINQ query?

View 1 Replies

C# - Get Access To An Incrementing Integer During LINQ Select

Dec 1, 2009

[Code]...

I am trying to replace tasks.IndexOf(t) + 1 with something a little simpler. Is there any built in functionality for this? Hrmm xml literals do not seem to translate well on here....

View 3 Replies

C# - LINQ - Select All In Parent-child Heirarchy

Mar 12, 2012

I was wondering if there is a neat way do to this, that DOESN'T use any kind of while loop or similar, preferably that would run against Linq to Entities as a single SQL round-trip, and also against Linq To Objects. I have an entity - Forum - that has a parent-child relationship going on. That is, a Forum may (or in the case of the top level, may not) have a ParentForum, and may have many ChildForums. A Forum then contains many Posts.

What I'm after here is a way to get all the Posts from a tree of Forums - i.e. the Forum in question, and all it's children, grandchildren etc. I don't know in advance how many sub-levels the Forum in question may have. (Note - I know this example isn't necessarily a valuble use case, but the Forum object model one is one that is familar to most people, and so serves as a generic and accessible premise rather than my actual domain model.)

View 2 Replies

Dynamic Variables In Linq Select Statement?

Nov 23, 2009

I have a listbox that is dynamically filled by certain values depending on what table has been selected from another list box. Once a value is selected, it is being graphed vs a date & time range. With my ignorance of linq: depending on what value is selected, the linq to sql statement I need to create to grab data from my database is different as I can't use an index on an anonymous type.

result = From t In db.APS _
Where t.DateTime >= startDate And _
t.DateTime <= finishDate And t.Weight = weight _
Select t.DateTime, t.TotalConcentration

t.TotalConcentration should be selected if my listbox value is "Total Concentration", but if it's something else, like "Temperature" or "Flow Rate" (connected to appropreate database columns) - this method obviously isn't going to work. I need to be able to dynamically select a specific column from the anonymous type list, or use some other method I'm unaware of to do this.

View 1 Replies







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