zoukankan      html  css  js  c++  java
  • 比较两个DataTable是否相等

            ///   <summary>
            ///   比较两个DataTable内容是否相等,先是比数量,数量相等就比内容
            ///   </summary>
            ///   <param   name= "dtA "> </param>
            ///   <param   name= "dtB "> </param>
            private bool CompareDataTable(DataTable dtA, DataTable dtB)
            {
                if (dtA.Rows.Count == dtB.Rows.Count)
                {
                    if (CompareColumn(dtA.Columns, dtB.Columns))
                    {
                        //比内容
                        for (int i = 0; i < dtA.Rows.Count; i++)
                        {
                            for (int j = 0; j < dtA.Columns.Count; j++)
                            {
                                if (!dtA.Rows[i][j].Equals(dtB.Rows[i][j]))
                                {
                                    return false;
                                }
                            }
                        }
                        return true;
                    }
                    else
                    {
                        return false;
                    }
                }
                else
                {
                    return false;
                }
            }
            ///   <summary>
            ///   比较两个字段集合是否名称,数据类型一致
            ///   </summary>
            ///   <param   name= "dcA "> </param>
            ///   <param   name= "dcB "> </param>
            ///   <returns> </returns>
            private bool CompareColumn(System.Data.DataColumnCollection dcA, System.Data.DataColumnCollection dcB)
            {
                if (dcA.Count == dcB.Count)
                {
                    foreach (DataColumn dc in dcA)
                    {
                        //找相同字段名称
                        if (dcB.IndexOf(dc.ColumnName) > -1)
                        {
                            //测试数据类型
                            if (dc.DataType != dcB[dcB.IndexOf(dc.ColumnName)].DataType)
                            {
                                return false;
                            }
                        }
                        else
                        {
                            return false;
                        }
                    }
                    return true;
                }
                else
                {
                    return false;
                }
            }

  • 相关阅读:
    人工智能芯片支持超低功耗器件的推理
    新十年嵌入式音频的五大趋势
    面向汽车应用的硬件推理芯片
    MySQL优化技巧总结
    JAVA集合类汇总
    为什么HashMap初始大小为16,为什么加载因子大小为0.75,这两个值的选取有什么特点?
    ztree 树状图——例
    amazeUI表单提交验证--input框required
    bigcolorpicker 颜色拾取器插件——例
    博客园-去掉皮肤
  • 原文地址:https://www.cnblogs.com/shenbing/p/6823403.html
Copyright © 2011-2022 走看看