The function to be used in the project, the code is pasted.
What to note: When configuring Web.config, pay attention to the version problem!
If the data source is configured in Web.config, the following <add key= "excelconnectionstring value=" provider=microsoft.jet.oledb.4.0; Data source= ' Miroexcel/info.xls '; Extended properties= ' Excel 8.0;
hdr=yes;imex=2 ' "/>///<summary>///read Excel file incoming absolute path query conditions///</summary>
<returns>DataSet</returns> Public DataSet Getboolexceldal (string cardid, String excelpath) {try {string strcon = ' provider=microsoft.ace.oledb.12.0; Data Source = ' + Excelpath + '; Extended properties= ' Excel 12.0;
Hdr=yes;imex=2 ' ";
OleDbConnection Conn = new OleDbConnection (Strcon); String strSQL = String.
Format ("select * from [sheet1$] where cardid= ' {0} '", Cardid);
Conn.Open ();
OleDbCommand Olecommand = new OleDbCommand (strSQL, Conn);
OleDbDataAdapter oleadapter = new OleDbDataAdapter (Olecommand);
DataSet ds = new DataSet (); Oleadapter.fill (ds, "Exceldata");
if (ds!= null) {return DS;
else {return null;
} catch (Exception ex) {return null; }
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/net/