Ado. NET reads an Excel file and acts as a data source

Source: Internet
Author: User

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/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.