帮定execl到DataSet

  加命名空间
using System.Data.OleDb; 

 private DataSet InExecl()
    {
        //string filename = get.filenames;
        string filename = Label2.Text;
        DataSet ds = new DataSet();
        string connStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("uplode" + "\\" + filename) + "; Extended Properties=Excel 8.0;";

        OleDbConnection myConn = new OleDbConnection(connStr);
        myConn.Open();
        DataTable dt = myConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
        string tableNamess = dt.Rows[0][2].ToString().Trim();

        string strSQL = " SELECT username,mobile from [" + tableNamess + "] ";


        OleDbDataAdapter myCommand = new OleDbDataAdapter(strSQL, myConn);
        DataSet myDataSet = new DataSet();
        myCommand.Fill(myDataSet,tableNamess );
        myConn.Close();

        return myDataSet;
    }
posted @ 2011-04-16 23:14  小锋神  阅读(722)  评论(0编辑  收藏  举报