1

切断されたクラスを使用して作成されたメモリ内データベースがあります。データ テーブルにデータを入力しました。次に、データ テーブルから特定の行を選択するクエリを実行します。最も簡単な方法は何ですか?

4

1 に答える 1

0

C# を使用DataTableしていて、たとえば次のようにクエリを実行できる場合:

private void GetRowsByFilter()
{
    DataTable table = DataSet1.Tables["Orders"];
    // Presuming the DataTable has a column named Date.
    string expression;
    expression = "Date > #1/1/00#";
    DataRow[] foundRows;

    // Use the Select method to find all rows matching the filter.
    foundRows = table.Select(expression);

    // Print column 0 of each returned row.
    for(int i = 0; i < foundRows.Length; i ++)
    {
        Console.WriteLine(foundRows[i][0]);
    }
}

例: http://msdn.microsoft.com/en-GB/library/det4aw50.aspx

LINQ を使用してコレクションをクエリすることもできます。DataTable.AsEnumarable

于 2012-06-14T06:56:55.153 に答える