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

     

    注:此文章转载至白衣轩

  • 相关阅读:
    函数中this指向问题及函数不同方式的调用
    拷贝继承
    组合继承
    借用构造函数
    继承
    UVA-11054(扫描法)
    hihocoder-1347 小h的树上的朋友(lca+线段树)
    UVA-10391(字符串检索)
    UVA-10125(中途相遇法)
    UVA-10827(前缀和降维)
  • 原文地址:https://www.cnblogs.com/hailexuexi/p/1903588.html
Copyright © 2011-2022 走看看