This question already has answers here:
how to get second record in linq to sql
(9 answers)
Closed 8 years ago.
I need to select rows 50 to 100 from a datatable. I have tried for the first 50 rows using this code:
dt.Rows.Cast<System.Data.DataRow>().Take(50)
Now I need rows 50 to 100 from the datatable. How do I do this?
Use Skip method
dt.Rows.Cast<System.Data.DataRow>().Skip(50).Take(50)
Related
This question already has answers here:
How to get first N elements of a list in C#?
(7 answers)
Closed 4 years ago.
I have a list of objects in which each object has a property called "Frequency" and I want to be able to pick the top 10 objects that have the highest frequencies.
I saw some solutions that are kind of similar to what I am looking to solve using LINQ so any help is appreciated.
You can order the list by descending Frequency and then take the first 10 like this:
var top10 = objectList.OrderByDescending(o => o.Frequency).Take(10);
This question already has answers here:
What is an IndexOutOfRangeException / ArgumentOutOfRangeException and how do I fix it?
(5 answers)
Closed 6 years ago.
I am trying to create a two dimensional numeric array in c#. In which there are the following simple methods: generates the array, shows the array results in the console and finally counts and shows the sum of all of the rows and columns in it.
But when i am trying to get the sums of rows and columns i get this error:
The number of rows and columns are specified in the first row of the data.txt file.(5 rows and 7 columns)
The data.txt file looks like this:
This is my first post in SOF so i apologize for any mistakes.
thanks in advance.
Assuming column count != row count - it should be
result = new int[columns] instead of result = new int[rows]
since you initialize result with result = new int[rows] and i is iterating the columns
This question already has answers here:
Distinct in Linq based on only one field of the table
(10 answers)
Closed 7 years ago.
In LINQ if the result that I have is the a list of whole records from the database and I want to do a Distinct on one column of this record, How do I do that?
You could try something as simple as:
var distincts = records.Select(x=>x.ColumnName).Distinct();
This question already has answers here:
How can I get the sum of multiple datetime values?
(2 answers)
Closed 8 years ago.
i have a table which contain a column NoofHours and data type is in datetime now i want to sum the values like 9:30 + 9:45 = 19:15(HH:MM) Format kindly Help.
Select sum(NoofHours) as sumO
FROM YourTable
Group By NoofHours
this should work for you:
SELECT convert(time,DATEADD(hh,SUM(DATEPART(hh,CONVERT(DATETIME,tm,108))), DATEADD(n,SUM(DATEPART(n,CONVERT(DATETIME,tm,108))),'1900.01.01') )) FROM temp
I've also created a SQLFiddle for you to test with SQLFIDDLE HERE
This question already has answers here:
Entity Framework. Delete all rows in table
(25 answers)
Closed 9 years ago.
I want to delete all records from my SQL Server table. I use LINQ to EF5. Is there anything I can do to do that?
context.Entities.DeleteAllOnSubmit(dc.Entities);