(C #) Return to DataSet from Excel [转]

xiaoxiao2021-03-06  65

public DataSet GetExcel (string Path) {// DirectoryInfo parsedirect = new System.IO.DirectoryInfo (Path); // FileInfo [] xlsfile = parsedirect.GetFiles ( "* xls."); OleDbConnection objConn = null; DataSet data = new DataSet (); try {string strConn = "provider = microsoft.jet.OLDB.4.0;" "Data Source =" PATH "; extended Properties = Excel 8.0;"; objconn = new oledbconnection (strconn); ObjconnN.Open (); DataTable schemaTable = objConn.GetOleDbSchemaTable (System.Data.OleDb.OleDbSchemaGuid.Tables, null); string tableName = schemaTable.Rows [0] [2] .ToString () Trim ();. string strSql = "Select * From [ " tableName "] "; OleDbCommand objCmd = new OleDbCommand (strSql, objConn); OleDbDataAdapter sqlada = new OleDbDataAdapter (); sqlada.SelectCommand = objCmd; sqlada.Fill (data," BuyPrice "); objConn.Close () Catch {Objconn.close (); throw;} return data;}

转载请注明原文地址:https://www.9cbs.com/read-119282.html

New Post(0)