Datatable Grouping Using Linq?
May 25, 2011
I'm completely dense here, but I'm trying to get some stats from a DataTable. One of the columns in the datatable is called "colour".I need to find out how many of each instance of "colour" are in the datatable.
I'm trying:
Dim q = From p In PGWorkingDataTable _
Group p By p("colour") Into Group _
[code].....
View 2 Replies
ADVERTISEMENT
Feb 5, 2010
I'm having a heck of a time with transforming a simple SQL Query into a LINQ query(using vb btw)
Here is my SQL:
SELECT USRDEFND5
FROM int_gp_employee
GROUP BY USRDEFND5
[Code]...
I've tried a number of different variations of the LINQ. My current statement is:
From b In xmlFile...<row> Group b...<usrdefnd5> By b...<usrdefnd5> INTO group when I foreach through the resulting collection, EVERY line (17000) shows up.
View 2 Replies
Aug 10, 2009
I am trying to summarize a datatable based on a primary column and then add certain columns. For example this table
col-1 col-2 col-3
1 AA 2
2 BB
[Code].....
This simply doesn't do anything becuase it thinks the target table doesn't have a primary key.
View 1 Replies
Jul 7, 2009
I've a large table of Items and I need to organize them by Category, then by Year and then by Month.Item has CategoryID and Dated properties.I got this far:
Dim Items = From Item In DB.Items _
Group By CategoryID = Item.CategoryID _
Into Categories = Group _
Order By CategoryID
But where I put the:
Group By Year = Year(Item.Dated)
and the
Group By Month = Month(Item.Dated)
The final result should be something like this:
For Each Category in Categories
For Each Year in Category.Years
[code].....
View 2 Replies
Aug 15, 2011
I have a table called Ordersthe table has many rows but im only interested in two in particular.I want to query the table so it returns the average ordered count of each producti want to know what is the average count of the ordered products, but now in total but per productID instead.
View 1 Replies
Jun 26, 2011
I need to take a collection and group it via Linq but all the examples I've seen fail in some manner or other with some syntax difference that I can't quite lick.
My collection:
Dim a As New List(Of ProcessAlert)
a.Add(New ProcessAlert("0000112367", "5551110000@txt.att.net", "Alert", 2))
a.Add(New ProcessAlert("0000112367", "5551110000@txt.att.net", "Document", 2))
[Code].....
View 1 Replies
Nov 17, 2009
I am struggling with a nullable datetime column [DateInsp] in an ASP.NET app which uses SubSonic3, Linq, MS SQL Server 2005.I had this all working when the datetime column [DateInsp] did not allow nulls. A new requirement forced me to set the [DateInsp] column to allow nulls and now I am struggling getting this piece of functionality to work properly again.
Problem 1:I need to first render a dropdown list of the 7 most recent inspection dates for a given inspector (this is a grouped list of the 7 most recent dates for the inspector). Here is the TSQL that I need to convert to Linq syntax:
declare @InspectorID varchar(5)
set @InspectorID = 'GPA'
select top 7 convert(nvarchar(30), [DateInsp], 101) InspectedDate
[code]....
If I can't get this work properly using Linq, BUT I can/could build a stored proc to return the list of dates and throw that into a dropdown. Fair enough. I've been fighting with the Linq syntax?
Problem 2: I need to use the selected date in the dropdown mentioned above to pull the correct records for this inspector and the correct date. Again, this is a nullable datetime field and this is real sticking point for me.
Here was the original Linq syntax that accomplished the requirement before I had to change the datetime field to allow Nulls:
Dim query = (From i In db.IncomingInspections _
Where i.InspectorID = User.Identity.Name _
Group By Key = New With {i.DateInsp} Into Group _
[code]....
For some reason I can't use the .Value property; I get: The member 'Value' is not supported I get: "Incorrect syntax near '<'." if I try to add the date comparison to the where clause too.
View 2 Replies
Aug 9, 2010
I have the following table structure. I want to select distinct CustomerId and CustomerName, TotalCost.[code]
View 2 Replies
Nov 9, 2011
I'm very new to linq and I'm trying to come up with a linq query against a dataset that will return a max count value based on grouping records.[code]...
View 1 Replies
May 24, 2010
I'm having trouble getting my head around converting a traditional SQL aggregate query into a LINQ one. The basic data dump works like so:
Dim result =
(From i As Models.InvoiceDetail In Data.InvoiceDetails.GetAll
Join ih As Models.InvoiceHeader In Data.InvoiceHeaders.GetAll On i.InvoiceHeaderID Equals ih.ID
[CODE].....................
What I need to really be getting out is ih.Period (a value from 1 to 12) and a corresponding aggregate value for i.ExtendedValue. When I try to Group ih I get errors about i being out of scope/context.
View 1 Replies
Apr 24, 2012
I've got the below, where I'm grouping a collection by a propery, then wanting to access the properties of my group. Problem I have is with the anonymous typing. Because of option strict I have to give an explicit type but I can't work out what the type should be. The below doesn't compile because t.HeadAccountKey isn't a value (as t has a type of object). So either I need do some casting or my linq selector is wrong,
[Code]....
View 1 Replies
Feb 10, 2010
I'm trying to convert DataTable to Linq using
DIm result = From r in dt.AsEnumerable()
Select new ( col1 = r.Field<integer>("id"), col2 = r.Field<string>("desc"))
But i get error near 'new (' saying type expected.
View 2 Replies
Apr 16, 2009
I found the following example on [URL] Unfortunately, I need it in VB and it's using some constructs that neither I nor the automated code converters reciognize. Anyone out there know how this should be written in VB.Net? (the problem spot is the "select new {...")
PeopleDataSet ds = new PeopleDataSet();
using (PeopleDataContext context = new PeopleDataContext())
{
[Code].....
View 4 Replies
Apr 24, 2012
I need help converting datatable to xml using Linq. I could do it with hardcoded column names as you can see in my code .. but i need it without hardcoding it ..Example datatable ..My linq query ..
Dim xmlDoc As New XDocument(
From row In dt.AsEnumerable()
From row In dt.AsEnumerable()[code]......
View 1 Replies
Jan 23, 2009
Why does the following code give an error?
[Code]...
If I change the code to remove the second field, as below, then the code does not give an error.
[Code]...
View 5 Replies
Sep 21, 2010
discovered the compact mode of this instructions vs usual code. I found sample code for selecting, etc. from a datatable, transforming a column in a list or array - all operations are "Select"s - readonly.I need to make an simple update on a certain rows (using LINQ) from a DISCONNECTED datatable for which now I'm using this
for each dr as datarow in dtable.Rows
dr("MyField") = 77
next
[code].....
View 16 Replies
Jan 13, 2011
I have two DataTables:
dt1 - personid, name
dt2 - personid
I want to create a third datatable to include records from dt1 when they are NOT in dt2 using LINQ. In this case, I can bind the third datatable to a dropdownlist.
View 1 Replies
Jan 21, 2011
Am new to the concept Linq.I created a var where i joined 3 tables to get the data and then bind it in a datatable and create a csv file. Now i want to use an additioanl table in the same variable to be bind with the datatable but my problem is i cant use join here since i dnt have any common col or primary col in this additional table.How do i add this extra table?
[Code]...
View 2 Replies
Apr 20, 2009
I'm writing a small web app in VB.NET and I would like to do paging for my DataTable in the following function :
Public Shared Function Testing(ByVal KeyWord As String, ByVal CurrentPage As Integer, ByVal PageSize As Integer) As DataTable
Dim db As New BibleDataClassesDataContext
[code].....
View 1 Replies
Jan 24, 2012
Currently, I am using a loop to find the row I want to update.
Public Sub pubsub_SetUserDGVColumnWidth(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewColumnEventArgs)
' update all user settings for the given column
[Code]....
View 8 Replies
Jan 7, 2012
I have a Dynamic DataTable Created at runtime. The Setup is like so
Id | Name | Age
-----------------
3 | Mike | 21
6 | John | 43
8 | Sara | 34
What I am trying to do is come up with a linq statement I could use to find and update specific rows.
Such as a statement to change AGE to '33' WHERE ID = '3'
My code So far is:
-[VB.NET]-
Dim MyRow As DataRow = From column In MyTable.Rows Where column("Id") = 3
MyRow(0)("Age") = 33
But this is not updating my DataTable entry.
View 2 Replies
Dec 22, 2009
I wish to output an IEnumerable type (dictionary(of T) would be perfect, otherwise a datatable would be acceptable) that provides an aggregation of the data within the datatable.In SQL I would write the query as such: select groupByColumn, sum(someNumber) from myTable group by groupByColumn
In VB.NET the closest I have got to this (achieved using information here) is: dt is a datatable containing two columns, referred to by index in p below Dim q = From p In dt Group p By p(0) Into Sum(p(1)) Select p(0), SumOfNumber = Sum
However I receive error: "Range variable name can be inferred only from a simple or qualified name with no arguments." on the p(0) element. Therefore my question is as follows:How can I resolve this error? How do I process the result (q) as an IEnumerable type? Life isn't made any easier because I'm using Linq in unfamiliar vb.net. Many examples are in C#, but I haven't really come across anything suitable even in C#.
View 1 Replies
Jul 8, 2010
i want to use linq to fetch data from datatable.I have 2 tables in Cache and i want to join these tables then get value from resultset.I pasted Original Sql query and my linq query here.My linq query returns nothing.Where do i miss?My original sql query returns 1 row,but q1 is nothing
[Code].....
View 1 Replies
Aug 2, 2011
I write the code below. I want to make short using linq count.
Dim query0 = From obj In dtAginglist _
Where (obj.Field(Of String)("CurrentStatus") = "Open" Or obj.Field(Of String)("CurrentStatus") = "Acknowledge") _
[Code]....
I try to use code below but it dosen't work with if source is datatable.
Dim orderCounts = From c In customers New With { _
c.CustomerID, Key .OrderCount = c.Orders.Count() }
View 1 Replies
Feb 21, 2012
syntax of the LINQ query to use GROUP something BY something and select some fields of the datatable. i am having a datatable filled with some rows, i am trying to fill the datagridview with the GROUP BY query output of some fields.
View 4 Replies
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
Jul 20, 2010
How can i write this query with LINQ to a FoxPro database?SELECT count(*) FROM Table group by item1I wrote it as below, but it doesn't work
Dim Query
Dim dt As New DataTable
Dim da = New Odbc.OdbcDataAdapter("SELECT * FROM table1",connection)
[code].....
View 3 Replies
Nov 3, 2009
I am looking for sample linq code snippet which uses System.Linq.Dynamic against a datatable.
Dim entities = (From ent In dt.AsEnumerable().Where(String.Format("IsUSFederal == {0}", "true")) _
Select Description = ent("Description"), Acronym = ent("Acronym")).ToList
I am getting an error "there is no accessible Where can be called with these arguments". I have included the DynamicLinq.vb file and the application compiles fine (aside from this error). I have included Imports System.Linq.Dynamic but it doesn't appear to be working.
View 1 Replies
Feb 18, 2010
I have an SQL table(for example, it have 1 column "kod" with 3 rows:1,2,3 ). To operate it, I used class LINQ to SQL and I create tmp dataset with one table, with one column "col" with values - 2,3,4. To operate with this tmp table i use IEnumerable(T).I want to find only new values in tmp table and write its in SQL table. To find this values, i want to use LINQ query. Queris to each table are worked well. But query for 2 tables don't work.
Imports System.Linq
Imports System.Data.Linq
Public Class Form1
[code]....
View 5 Replies
Mar 2, 2012
I am trying to convert my EnumerableRowCollection into a DataTable, but I can't see the CopyToDataTable method. The enm.CopyToDataTable() has the blue saw tooth line under it with error saying " 'CopyToDataTable' is not a member of 'System.Data.EnumerableRowCollection' ". I have set a Reference to System.Data, System.Data.Linq, and System.Data.DataSetExtensions. I thought the CopyToDataTable method was part of the System.Data.DataSetExtensions, right? Anyone know why I can't access this method?
[Code]...
View 7 Replies