国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費電子書等14項超值服

開通VIP
DataTable的Select方法

DataTable的Select方法

DataTable的Select方法

獲取 DataRow 對象的數(shù)組。

重載列表
名稱                    說明
Select()               獲取所有 DataRow 對象的數(shù)組。
Select(String)      
                             按照主鍵順序(如果沒有主鍵,則按照添加順序)獲取與篩選條件相匹配的所有 DataRow 對象的數(shù)組。  

Select(String, String)                                           
                             獲取按照指定的排序順序且與篩選條件相匹配的所有 DataRow 對象的數(shù)組。
Select(String, String, DataViewRowState)
                              獲取與排序順序中的篩選器以及指定的狀態(tài)相匹配的所有 DataRow 對象的數(shù)組。

示例:

private void GetRows()
{
    // Get the DataTable of a DataSet.
    DataTable table = DataSet1.Tables["Suppliers"];
    DataRow[] rows = table.Select();

    // Print the value one column of each DataRow.
    for(int i = 0; i < rows.Length ; i++)
    {
        Console.WriteLine(rows[i]["CompanyName"]);
    }
}

//**********************************************************************************************************

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]);    }}

//**********************************************************************************************************

private void GetRowsByFilter()
{
    DataTable table = DataSet1.Tables["Orders"];

    // Presuming the DataTable has a column named Date.
    string expression = "Date > '1/1/00'";

    // Sort descending by column named CompanyName.
    string sortOrder = "CompanyName DESC";
    DataRow[] foundRows;

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

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

//**********************************************************************************************************

    private static void GetRowsByFilter()
    {
        DataTable customerTable = new DataTable("Customers");
        // Add columns
        customerTable.Columns.Add("id", typeof(int));
        customerTable.Columns.Add("name", typeof(string));

        // Set PrimaryKey
        customerTable.Columns[ "id" ].Unique = true;
        customerTable.PrimaryKey = new DataColumn[]
            { customerTable.Columns["id"] };

        // Add ten rows
        for(int id=1; id<=10; id++)
        {
            customerTable.Rows.Add(
                new object[] { id, string.Format("customer{0}", id) });
        }
        customerTable.AcceptChanges();

        // Add another ten rows
        for(int id=11; id<=20; id++) { customerTable.Rows.Add( new object[] { id, string.Format("customer{0}", id) });
        }

        string expression;
        string sortOrder;

        expression = "id > 5";
        // Sort descending by column named CompanyName.
        sortOrder = "name DESC";
        // Use the Select method to find all rows matching the filter.
        DataRow[] foundRows =
            customerTable.Select(expression, sortOrder,
            DataViewRowState.Added);

        PrintRows(foundRows, "filtered rows");

        foundRows = customerTable.Select();
        PrintRows(foundRows, "all rows");
    }

    private static void PrintRows(DataRow[] rows, string label)
    {
        Console.WriteLine("\n{0}", label);
        if(rows.Length <= 0)
        {
            Console.WriteLine("no rows found");
            return;
        }
        foreach(DataRow row in rows)
        {
            foreach(DataColumn column in row.Table.Columns)
            {
                Console.Write("\table {0}", row[column]);
            }
            Console.WriteLine();
        }
    }

本站僅提供存儲服務,所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊舉報。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
c# 將DataGridViewRows轉(zhuǎn)換為DataTable數(shù)據(jù)
DataTable轉(zhuǎn)成實體列表 和 DataRow轉(zhuǎn)成實體類
DataRow的序列化問題
DataSet與DataReader的區(qū)別解讀
asp.net Mvc Npoi 導出導入 excel
DataTable的函數(shù)
更多類似文章 >>
生活服務
分享 收藏 導長圖 關(guān)注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點擊這里聯(lián)系客服!

聯(lián)系客服