zoukankan      html  css  js  c++  java
  • DataTable帮助类

    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Data;
    using System.Data.SqlClient;
    using Microsoft.Office.Interop.Excel;
    using Microsoft.Office.Interop.Word;
    using System.Collections;
    using System.IO;
    namespace Common
    {
        public class DataSetOperation
        {
             string exceptionMessage;//定义异常信息
             DataSetOperation()
            {
            }

            #region 连接两个具有相同数据结构的DataTable,返回DataTable
            /// <summary>
            /// 连接两个具有相同数据结构的DataTable,返回DataTable
            /// </summary>
            /// <param name="table1"></param>
            /// <param name="table2"></param>
            /// <returns></returns>
            public  System.Data.DataTable GetInnerDataTable(System.Data.DataTable table1, System.Data.DataTable table2)
            {
                table1.Merge(table2);
                return table1;
            }
            //将数据集写入xml文件
            public  bool WriteDataSetToXml(DataSet dataset,string filename)
            {
                try
                {
                    dataset.WriteXml(filename);
                    return true;
                }
                catch(Exception ex)
                {
                    exceptionMessage = ex.Message;
                    return false;
                }
            }
            #endregion

          

            #region 查询DataTable中的数据
            /// <summary>
            /// 查询DataTable中的数据
            /// </summary>
            /// <param name="table">要查询的datatable</param>
            /// <param name="comText">查询条件</param>
            /// <returns>数据列集合</returns>
            public DataRow[] GetSelectDataTable(System.Data.DataTable table,string comText)
            {
                try
                {
                    DataRow[] rows = table.Select(comText);
                    return rows;
                }
                catch (Exception ex)
                {
                    exceptionMessage = ex.Message;
                    return null;
                }
            }
            #endregion

            #region 设置或取得异常信息
            /// <summary>
            /// 设置或取得异常信息
            /// </summary>
            public string ExceptionMessage
            {
                get
                {
                    return exceptionMessage;
                }
                set
                {
                    exceptionMessage = value;
                }
            }
            #endregion
        }
    }

     

    注:此文章转载至白衣轩

  • 相关阅读:
    区块链的入门
    数组元素查找(查找指定元素第一次在数组中出现的索引)
    数组查表法之根据键盘录入索引,查找对应星期
    数组元素反转
    数组获取最大值
    数组的遍历
    数组操作的两个常见小问题越界和空指针
    方法重载练习比较数据是否相等
    方法之根据键盘录入的数据输出对应的乘法表
    方法之根据键盘录入的行数和列数,在控制台输出星形
  • 原文地址:https://www.cnblogs.com/hailexuexi/p/1903588.html
Copyright © 2011-2022 走看看