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

 

注:此文章转载至白衣轩

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值