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 8048707
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T06:33:52+00:00 2026-06-05T06:33:52+00:00

I only want to return a certain number of rows into the DataTable via

  • 0

I only want to return a certain number of rows into the DataTable via LINQ’s Take or use it on the Rows property, but I am not sure how or where to do it: Here is the current code:

 Dim dt As DataTable = GetDataTable("sp", params)
 For Each dr As DataRow In dt.Rows
        Dim o As New OR()
        o.P = p
        o.Id = dr ("A")
        o.R = dr ("B")
 Next

Would it be something like:

Dim dt As DataTable = GetDataTable("sp", params).AsEnumerable().Take(10)

When I run the above, I get the error:

The 'TakeIterator' start tag on line 4 position 60 does not match the end tag of 'Error'. Line 4, position 137.

Unable to cast object of type '<TakeIterator>d__3a1[System.Data.DataRow]’ to type ‘System.Data.DataTable’.`

  • 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-06-05T06:33:55+00:00Added an answer on June 5, 2026 at 6:33 am

    If you need a DataTable:

    Dim dt As DataTable = (From row in GetDataTable("sp", params) Take 10).CopyToDataTable()
    

    If you need a List(Of [Or]) (you need the brackets since Or is a keyword)

    Dim list As List(Of [Or]) = (From row In GetDataTable("sp", params)
                                Select New [Or]() {
                                    o.Id = row.Field(Of Int32)("Id"),
                                    o.R =  row.Field(Of String)("R")
                                }).Take(10).ToList()
    

    Edit:

    is there a way I can also include a Where with the Take, for example, I have 3 statuses in my table, Open, Semi-Open, Closed, I only want to Take 10 for Open, but I want to leave Semi-Open and Closed alone. As an example Semi-Open and Closed will have 5 records combined and I will take 10 from Open, so I would get a total of 15 rows

    Yes, there’s a way:

    Dim dt =  GetDataTable("sp", params)
    Dim open10 = From row In dt
                 Where row.Field(Of String)("Status") = "Open"
                 Take 10
    Dim rest = From row In dt
               Where row.Field(Of String)("Status") <> "Open"
    Dim tblResult = open10.Concat(rest).CopyToDataTable()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to run a basic query, but return only the first ten rows
I want to implement all my own rotation animations but if I only return
I want regExp to test for two 'Hello'-s and return true but it only
I Want to execute a Certain Task to take only 1000 MS , if
I want to get only the rows with a unique value for a certain
I want to look up a word in multiple files, and return only a
How can I return the key?, mean if I want to allow only integer
document.onkeydown.toString() returns onkeydown function but I only want to get this function's name. Is
I only want this function to run if .toolbar li does not have the
I have a site where users upload data into it and I only want

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.