++

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

 

 

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.OleDb;

namespace DAL
{
  public    class exportExcelDAL
    {
   
      /// <summary>
      /// 执行Sql命令
      /// </summary>
      /// <param name="strCommand"></param>
      /// <param name="DataSource"></param>
      /// <returns></returns>
      public System.Data.DataTable exeCommand(string strCommand, string DataSource)
      {
          //strCommand = "SELECT " + strSelect + "FROM [" + strTableName + "$] " + strWhere + " " + strOrderBy;
          string sConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + DataSource + ";" + "Extended Properties=Excel 8.0;";
          System.Data.DataTable dt = null;
          try
          {
              using (OleDbConnection objConn = new OleDbConnection(sConnectionString))
              {
                  dt = new System.Data.DataTable();
                  objConn.Open();
                  OleDbDataAdapter adapter = new OleDbDataAdapter(strCommand, objConn);
                  dt = new System.Data.DataTable();
                  adapter.Fill(dt);
              }
          }
          catch (Exception)
          {
          }
          return dt;
      }

    }
}

 

 

posted on 2010-02-11 12:45  自制力缺失症患者  阅读(186)  评论(0)    收藏  举报