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
        }
    }

     

    注:此文章转载至白衣轩

  • 相关阅读:
    sed command
    【Python3】作用域(局部变量、全局变量)
    【Python3】函数与参数
    【Python3】编程范式
    【Python3】字符解码与编码
    【Python3】文件操作
    【Python3】集合
    【Python3】目录
    【Python3】字典
    【Python3】字符串操作
  • 原文地址:https://www.cnblogs.com/hailexuexi/p/1903588.html
Copyright © 2011-2022 走看看