Welcome

首页 / 软件开发 / .NET编程技术 / Excel转DataSet的一个例子

Excel转DataSet的一个例子2012-01-04 csdn博客 jinjazz
public static DataSet ExcelToDS(string Pathm,string TableName)    ...{      DataSet ds = new DataSet();      try      ...{        string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + Path + ";" + "Extended Properties=Excel 8.0;";        OleDbConnection conn = new OleDbConnection(strConn);        conn.Open();        string strExcel = "";        OleDbDataAdapter myCommand = null;        strExcel = string.Format("select * from [{0}$]",TableName);        myCommand = new OleDbDataAdapter(strExcel, strConn);          myCommand.Fill(ds, TableName);      }      catch(Exception ex)      ...{        System.Windows.Forms.MessageBox.Show(ex.Message);      }      return ds;    }