加命名空间
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; }