Click here to Skip to main content
15,884,353 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

1 solution

C#
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]);
    }
    }
}
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900