You can’t query against the DataTable
‘s Rows collection, since DataRowCollection
doesn’t implement IEnumerable<T>
. You need to use the AsEnumerable()
extension for DataTable
. Like so:
var results = from myRow in myDataTable.AsEnumerable() where myRow.Field<int>("RowNo") == 1 select myRow;
And as @Keith says, you’ll need to add a reference to System.Data.DataSetExtensions
AsEnumerable()
returns IEnumerable<DataRow>
. If you need to convert IEnumerable<DataRow>
to a DataTable
, use the CopyToDataTable()
extension.
Below is query with Lambda Expression,
var result = myDataTable .AsEnumerable() .Where(myRow => myRow.Field<int>("RowNo") == 1);
Related Posts:
- LINQ’s Distinct() on a particular property
- Extension methods must be defined in a non-generic static class
- Extension methods must be defined in a non-generic static class
- How do I concatenate two arrays in C#?
- Sequence contains more than one element
- Linq: GroupBy, Sum and Count
- .Net 4.8 Support for Windows 10 ends in 26 days?
- What is a NullReferenceException, and how do I fix it?
- How do I get a random YouTube video with the YouTube API?
- An existing connection was forcibly closed by the remote host
- How can I convert String to Int?
- What is a NullReferenceException, and how do I fix it?
- I am getting Failed to load resource: net::ERR_BLOCKED_BY_CLIENT with Google chrome
- IOException: The process cannot access the file ‘file path’ because it is being used by another process
- No connection could be made because the target machine actively refused it?
- Could not load file or assembly or one of its dependencies
- What does a lock statement do under the hood?
- Error : Could not load file or assembly or one of it’s dependencies
- Group by in LINQ
- Could not load file or assembly or one of its dependencies
- Priority queue in .Net
- What is the difference between int, Int16, Int32 and Int64?
- What is the purpose of nameof?
- How to open .dll files to see what is written inside?
- Windows .NET API / Windows 7 / Bluetooth communication with Intel Curie Arduino / Genuino 101
- Error 1053 the service did not respond to the start or control request in a timely fashion
- System.web.mvc missing
- Nullable object must have a value?
- Sequence contains no elements?
- Access to the path is denied
- ToList().ForEach in Linq
- Metadata file ‘.dll’ could not be found
- WebForms UnobtrusiveValidationMode requires a ScriptResourceMapping for jquery
- “Error while trying to run project: Unable to start program”. Can run program only once. Then VS needs restart
- How to resolve this System.IO.FileNotFoundException
- What is clr.dll on .Net framework and what does it do?
- what is this oleaut32.dll?
- Associating enums with strings in C#
- How do I declare a DefaultValue attribute whose value is an array of strings?
- Proper Linq where clauses
- How to resolve this System.IO.FileNotFoundException
- How can I get the application’s path in a .NET console application?
- How do I create a Shared Code project (.shproj)
- There is no argument given that corresponds to the required formal parameter – .NET Error
- Select distinct using linq
- How do I remedy “The breakpoint will not currently be hit. No symbols have been loaded for this document.” warning?
- Invalid URI: The format of the URI could not be determined
- Multiple file-extensions searchPattern for System.IO.Directory.GetFiles
- Convert Linq Query Result to Dictionary
- Could not establish trust relationship for SSL/TLS secure channel — SOAP
- Get single value from dictionary by key
- Unable to read data from the transport connection : An existing connection was forcibly closed by the remote host
- Why did I get the compile error “Use of unassigned local variable”?
- Reading CSV file and storing values into an array
- IEnumerable vs List – What to Use? How do they work?
- Sequence contains no matching element
- The remote server returned an error: (407) Proxy Authentication Required
- How to open a new form from another form
- HTML.ActionLink method
- Deep cloning objects
- Regular expression “^[a-zA-Z]” or “[^a-zA-Z]”
- .NET graph library around?
- How to split() a delimited string to a List
- Remove element of a regular array
- An object reference is required to access a non-static member
- Task vs Thread differences
- How can I know if a process is running?
- String was not recognized as a valid DateTime ” format dd/MM/yyyy”
- XmlSerializer – There was an error reflecting type
- Substring index and length must refer to a location within the string
- Run Command Prompt Commands
- windows could not start service on local computer error 5 access is denied
- Cannot implicitly convert type ‘System.Collections.Generic.List< >‘ to ‘System.Collections.Generic.IList< >‘
- Visual Studio keeps crashing
- How can I implement static methods on an interface?
- How do I exit a WPF application programmatically?
- How to convert UTF-8 byte[] to string
- .NET String.Format() to add commas in thousands place for a number
- Linq select objects in list where exists IN (A,B,C)
- Produce a random number in a range using C#
- Which passwordchar shows a black dot (•) in a winforms textbox?
- What is a quick way to force CRLF in C# / .NET?
- How do I fix a .NET windows application crashing at startup with Exception code: 0xE0434352?
- How to enable assembly bind failure logging (Fusion) in .NET
- How to make inline functions in C#
- How to properly make a http web GET request
- c# .net change label text
- How to create a new object instance from a Type
- Using FolderBrowserDialog in WPF application
- Is there an equivalent to the C# “var” keyword in C++/CLI?
- When should I use a List vs a LinkedList
- Playing a MP3 file in a WinForm application
- .NET Core vs Mono
- Iif equivalent in C#
- Quickest way to compare two generic lists for differences
- Best way to randomize an array with .NET
- Encrypt and decrypt a string in C#?
- Using .Select and .Where in a single LINQ statement
- Unrecognized escape sequence for path string containing backslashes
- How to enumerate an enum