且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从DataTable中查询数据

更新时间:2022-06-09 22:42:27

/// <summary>
    /// 从DataTable中查询数据
    /// </summary>
    /// <param name="tb">待处理的DataTable</param>
    /// <param name="expression">找匹配(条件)(不用where ,直接就"什么=什么")</param>
    /// <returns>符合你条件的DataTable</returns>
    public DataTable GetDataTableByFilter(DataTable tb, string expression)
    {
        DataRow[] foundRows;
        try
        {
            foundRows = tb.Select(expression);
        }
        catch (Exception err)
        {
            throw err;
        }
        return CopyData(foundRows, tb);
    }