Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6727253
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:01:41+00:00 2026-05-26T10:01:41+00:00

I want to order a DataTable with Linq to DataSet using two ordering values.

  • 0

I want to order a DataTable with Linq to DataSet using two ordering values. However the two values come from splitting and parsing the same field (don’t ask me why!).

I tried to do this:

var query = from row in dtReports.AsEnumerable()
            orderby row.Field<string>("ReportNumber").Substring(0,4),
                int.Parse(row.Field<string>("ReportNumber").Substring(5))
            select row

DataTable dt = query.AsDataView().ToTable()

But I got “Can not create DataView after using projection”.

Then I also tried with:

var query = from element in (
                from row in dtReports.AsEnumerable()
                let year = row.Field<string>("ReportNumber").Substring(0, 4)
                let num = int.Parse(row.Field<string>("ReportNumber").Substring(5))
                select row, year, num)
            orderby element.year, element.num
            select element.row

DataTable dt = query.AsDataView().ToTable()

and I keep getting the same error.

How could this be done?


I want to thank you all for your answers. The final solution is very simple:

var query = from row in dtReports.AsEnumerable()
            let year = row.Field<string>("ReportNumber").Substring(0, 4)
            let num = int.Parse(row.Field<string>("ReportNumber").Substring(5))
            orderby year, num
            select row

DataTable dt = query.CopyToDataTable()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T10:01:41+00:00Added an answer on May 26, 2026 at 10:01 am

    You can use CopyToDataTable:

    DataTable dt = query.CopyToTable()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to parse some HTML in order to find the values of some
I want to perform a JOIN on two Datatables in a Dataset. For example,
I'm using a table sorter to 'order' my tables on the client side. However
I want to order by Time,but seems no way to do that ? mysql>
I want to order a result by fieldx * fieldy , for example: Row
What do I put in my order by?? I want to order by Name.
I have a table: ID name c_counts f_counts and I want to order all
...@Sort bit) AS SELECT .............. and I want to Order only if Sort =
In a system with multiple concurrent tasks operating on data, I want to order
I want something simple in order to experiment/hack. I've created a lot interpreters/compilers for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.