DataSource Controls :: LINQ Query To Grab The Last 5 Rows From A Group?
Jan 8, 2010
i have the following objects:
Event:
- EventID (PK)
- GroupID (FK)
- StartDate
Group:
- GroupID (PK)
- GroupName
What i need to do is select the last 5 events for each group using LINQ to Objects. I tried starting with:
[Code]....
But i'm not sure how i only take the last 5 per group.
The simple way of doing this is to get the groups and then have a property on that which returns the last 5 events but if i databind this i will have to use a nested Repeater/ListView. Ideally i would like to have a row foreach event.
View 3 Replies
Similar Messages:
Jun 17, 2010
[Code]....
In above query I want to have top 10 rows as well as count of all rows.
View 3 Replies
Mar 26, 2010
I'm using a linq group by query (with two grouping parameters) and would like to use the resulting data in a nested repeater.
var dateGroups = from row in data.AsEnumerable()
group row by new { StartDate = row["StartDate"], EndDate = row["EndDate"] };
"data" is a DataTable from an SqlDataAdapter-filled DataSet. "dateGroups" is used in the parent repeater, and I can access the group keys using Eval("key.StartDate") and Eval("key.EndDate").
Since dateGroups actually contains all the data rows grouped neatly by Start/End date, I'd like to access those rows to display the data in a child repeater. To what would I set the child repeater's DataSource? I have tried every expression in markup I could think of; I think the problem is that I'm trying to access an anonymous member (and I don't know how.) In case it doesn't turn out to be obvious, what would be the expression to access the elements in each iteration of the child repeater? Is there an expression that would let me set the DataSource in the markup, or will it have to be in the codebehind on some event in the parent repeater?
View 3 Replies
Feb 8, 2010
I'm attempting to further reduce a dataset/table by various user input. Part of this process is grouping the data by a timestamp prior to a summation. I'm trying to use LINQ and cannot get the data returned that I need.
[Code]....
View 7 Replies
Mar 14, 2010
How do I translate the following query into LINQ to SQL?
[Code]....
View 1 Replies
Mar 10, 2010
select Groupid,GroupName,onorusername from palgroup where groupid in (select distinct Groupid
View 5 Replies
May 6, 2010
I have a table that contains image data type and has more than 20,000 records.I want to change its file group to the new file group. I tried to change it using table designer, but everytime I wanted to save it, it occured an error with this message:
[Code]....
Does anyone know how to change file group using Alter Table query? I'm using SQL Server 2005.
View 2 Replies
May 4, 2010
i have 2 tables company(companyId,companyName,City,state,country) and people(peopleId,peopleName,City,state,country) i want to display the total no of contacts and Total no of companies with respect to countries
i tried with group by: select country,count(*)companyId from company group by country is displaying the total number of companies with respect to country select country,count(*)peopleId from people group by country is displaying the total number of peoplewith respect to country
but i want to combine these two quries i want the output as :
Country Companies Contacts
India 10 5
USA 0 10 (usa is having only contacts ,i doesn' have the companies)
UK 8 0 (ukis having only companies ,i doesn' have the contacts)
View 2 Replies
Nov 26, 2013
Using a LINQ query and an aspx page with an Infragistics webdatagrid control, I am generating data that look like this:The data come from my dataset: There is another column which is TobaccoUse and it is N, Y, N, Y, N, Y, etc for each row. There is also a column for the rate, and it is 147.32 for all rows (test data). But it could and most likely will, especially as the ages increase, be different, like $250 for a 25-year-old smoker but $200 for a 25-year-old non-smoker.
The grid I want to present needs to collapse every two rows into one, so you see one row for 0-17 smoker and non-smoker, etc. I do not know how to write this query. I don't actually know how to write any LINQ query but I've enhanced some existing ones, or understood them, but it's easier to read something that exists than write it new or change it dramatically, which I believe I need to do.
The query right now is:
Code:
var medRateBook = from rates in dsMedRateBookRates.Tables[0].Rows.Cast<DataRow>()
select new
{
DivisionNum = div.DivisionNbr.Trim(),
Age = rates["agedesc"].ToString().Trim(),
TobaccoRate = rates["calcratePreferred"].ToString().Trim(),
[code]....
View 2 Replies
Jun 25, 2010
I´m using Linq to Sql in my asp.net application, but the problem is:I have a query like this:
[Code]....
My query is not returning anything, how do I do to get this?my problem is with this interval I need to have.
View 2 Replies
Jan 6, 2010
Is there any way to update multiple rows in a SQL query without using an foreach statement? In a single query.
View 3 Replies
Jun 11, 2010
I have an SQL database table like the following:
ID // Code // Shape
The ID is the integer identifier.
On one line the Code may be OX01 and shape Hexagon for example
Then the next line the code is still OX01 but the shape is Triangle.
What I want to do is be able to pull back data for every line that is equal to a unique Code column. in the above example OX01 Hexagon would be returned but not OX01 Triangle.
I've tried using SELECT DISTINCT but it brings back all records and doesn't filter them correctly.
I've considered having another column which could have Child/Parent data so that only the parent is returned but i'm sure there must be a better way of doing this.
View 2 Replies
Apr 8, 2010
i want to update many rows with difference values inside table. i'm coding a timetable.
View 3 Replies
May 31, 2010
I want to use from two db connection in one linq query
My sample is:
int a=1;
if(a==1)
DataClasses1DataContext1 db = new DataClasses1DataContext1();
else
DataClasses1DataContext2 db = new DataClasses1DataContext2();
var q =
from c
in db.F_Groups
select c;
In this code a=1 so db connection is DataClasses1DataContext1
I want if a=2 then db connection = DataClasses1DataContext2
but this code is error.
db connections is completely same but in two deferent class a db connection is sql and another is oracle
View 4 Replies
Feb 13, 2010
How can I convert this sql query to LINQ ?
[code]...
View 1 Replies
Feb 18, 2010
Im doing thing profile, zip code thing on my site. One table has a list of zipcodes and in the other is a profile and there they keep what zip code they entered. I already have the radius code but idk how to get a list of all the profiles in a radius.I'm going to store the zip codes that come back from the zip code table in a arraylist and put it in a session state so i don't have to keep getting the same thing over and over again. The problem is i don't know how to write the linq to sql query to take the arraylist of zip codes and look up all the users that have that as there set zip code in there profile.
View 1 Replies
Mar 12, 2010
Is there a way opf getting the first value from a linq query so for example
[Code]....
View 2 Replies
May 13, 2010
So I'm trying to add a single item to a query I wrote. The query is then pass to the e.Result of a LinqDataSource_Selecting event. This datasource is being used by a dropdown list and label in a listview.
I am trying to add a "New" field to the end of the list.
Currently I have this working, but it seems like a really messy solution. First I make a class with the fields I need:
[Code]....
Then I build the query:
[Code]....
Then a second list and query with the new value:
[Code]....
Finally, I union the two and set the e.Result:
[Code]....
View 5 Replies
Mar 20, 2010
I need to know how to extract the result of the attempted LINQ query below and set it equal to the strFile variable.Everything Intellisensed OK here but ine 5 shows a syntax error at the parenthesis.
[Code]....
View 12 Replies
Apr 7, 2010
I'm having a problem with a Linq query where is executing the second half of an OrElse even though the first half evaluates to true.
[Code]....
When Manufacturer is null, I get a NullReferenceException. The "Manufacturer.Trim()" should never be executed, because the first half of the OrElse evaluates to true. Just to test it out, I also tried this:
[Code]....
This actually works fine... Manufacturer.Trim() is never executed, and I get no error. Why is the Trim() statement being executed in the first case? If Manufacturer is null, then it shouldn't be.
View 4 Replies
Mar 29, 2010
I am working on a small project. I ran the query below to get the maximum userid and increase it by 1 to create a new userid. However, when I run the query, it does not display the values that I enter into the database using insert statement. For example, if I open the table called login, I can see there are three records. If Irun the select statement, it only return one record which is the one that I enter manually when I first created the table. If I run the same select statement and give it a user id that I created, it returns the correct result.
[Code]....
View 2 Replies
Jan 23, 2010
I have this LINQ query:
var agnts = (from a in db.agents select new { a.userid, a.name }).Take(10);
How can I get randomly get 10 records from my agents table?
I have tried:
agnts = agnts.OrderBy(n => Guid.NewGuid());
but this doesn't seem to do anything.
View 5 Replies
Jan 26, 2010
Need to figure out the correct way to do a simple SUM function in Linq, but also manipulate one of the feilds coming back by doing a Substring on it, here is the original SQL query:
[Code]....
View 1 Replies
Apr 23, 2010
As the title sugests, I am missing a (basic?) concept as I teach myself asp.net, linq, and C#. It has been awhile since I've done anything object oriented, so I don't know how much that is impacting this gap in my understanding. Anyhow, here is what I am trying to do. I have three SQL Server tables: PERSON, POSITION, AREA. There is a 1 to many relationship between PERSON and POSITION, and a 1 to 1 relationship between POSITION and AREA. Given the following code I verify who the person is who has logged into the browser:
[Code]....
I want to be able to return all of the AREAs the person is able to access, based on the position they currently hold. I am able to easily do this in a SQL Server query, and I am sure I can do this with a SQL stored procedure once I pass the EMPLOYEE_ID to the procedure. However, I would rather do this in the page_load event, and load the returned results into gridview1 for the viewer. The issue I am running into is in building the LINQ query. When I try to build it, I can only get access to two of the three tables, depending on which table I select with db. Is it possible to access all three tables in the same query?
View 10 Replies
Mar 1, 2010
I have a field name as a string and i want to find it in a linq query. so something like this
[Code]....
View 3 Replies