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

  • SEARCH
  • Home
  • 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 8487797
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T21:21:10+00:00 2026-06-10T21:21:10+00:00

I have a datatable where i am trying to do datatable.Select(Name Like ‘#%#’) but

  • 0

I have a datatable where i am trying to do
datatable.Select(Name Like ‘#%#’) but getting error that invalid pattern(expecting result of a table with name col having #Mike#,#Brow#..). Using escape sequense dint for all items dint work fine too. Many suggest to use Linq – but am new to it. How can i do this filter with Linq from this datatable.

This is a sample of what i was trying to do..

 Dim dtSamp As Data.DataTable
    dtSamp = New Data.DataTable
    dtSamp.Columns.Add("Name")
    dtSamp.Columns.Add("Marks")

    Dim dr As DataRow
    dr = dtSamp.NewRow()
    dr.Item(0) = "AAA"
    dr.Item(1) = "50"
    dtSamp.Rows.Add(dr)
    dr = dtSamp.NewRow()
    dr.Item(0) = "#bbb#"
    dr.Item(1) = "60"
    dtSamp.Rows.Add(dr)
    dr = dtSamp.NewRow()
    dr.Item(0) = "ccc"
    dr.Item(1) = "44"
    dtSamp.Rows.Add(dr)

    Dim drResult As DataRow()
    drResult = dtSamp.Select("Name Like '#%#'")

    Dim dtOutPutTable As Data.DataTable
    dtOutPutTable = drResult.CopyToDataTable()

In the dtOutPutTable i was expecting 1 row ie, #bbb# in it.. but the Select function fails.

  • 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-10T21:21:12+00:00Added an answer on June 10, 2026 at 9:21 pm

    Generally LINQ queries works on data sources which implement the IEnumerable<T>/ IQueryable<T> Interface. But DataTable does not implement any of these. So we can not directly apply LINQ queries on a DataTable.

    But DataTable class has an extension method called AsEnumerable which returns an IEnumerable collection of DataRow. So we can apply the AsEnumerable function on a DataTable and then play with some LINQ on the resulting collection.

    var items=(from p in myDataTable.AsEnumerable()
                     select new { ID= p.Field<int>("ID").
                                  Name=p.Field<string>("Name")
                               }).ToList();
    var filtered=items.Where(x => x.Name.Contains("Mike"));
    

    EDIT : Here is the VB.NET Version ( Disclaimer: I am not a VB.NET guy. but i could build this code without any error)

    Dim items = (From p In myDataTable.AsEnumerable() 
                   Select New With {.ID = p.Field(Of Integer)("ID"),
                                    .Name = p.Field(Of String)("Name")}).ToList()
    
    Dim filtered = items.Where(Function(x) x.Name.Contains("Mike")).ToList()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a datatable and trying to insert that datatable through SqlBulkCopy but
I have a Datatable in my C# program that I would like to INSERT
I have a DataTable that contains a multi-select choice field (string). Values in the
Hi I have a problem, when I am trying to use DataTable.Select to get
I have been trying to use OleDbDataAdapter to update a DataTable but got confused
I have acefaces datatable with file names, one on row and I'm trying to
I have datatable with column name tag and 100 rows of data.I need to
I have a DataTable MyDT like below: string MyConString = SERVER= + sConfig_hostname +
I have a datatable that stores location values as such: CTY_CD, STATE_CD, COUNTRY_CD and
We have a third-party DLL that can operate on a DataTable of source information

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.