Click here to Skip to main content
12,884,480 members (31,849 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# ASP.NET
I have a datatable and i have around 100 rows. i want to have a select query for datatable for one value in Cell to get all the rows where the value of the cell matches.
Posted 7-Feb-13 22:39pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

using System;
using System.Data;
class Program
    static void Main()
    // Create a table of five different people.
    // ... Store their size and sex.
    DataTable table = new DataTable("Players");
    table.Columns.Add(new DataColumn("Size", typeof(int)));
    table.Columns.Add(new DataColumn("Sex", typeof(char)));
    table.Rows.Add(100, 'f');
    table.Rows.Add(235, 'f');
    table.Rows.Add(250, 'm');
    table.Rows.Add(310, 'm');
    table.Rows.Add(150, 'm');
    // Search for people above a certain size.
    // ... Require certain sex.
    DataRow[] result = table.Select("Size >= 230 AND Sex = 'm'");
    foreach (DataRow row in result)
        Console.WriteLine("{0}, {1}", row[0], row[1]);

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170422.1 | Last Updated 8 Feb 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100