C # converts data from Excel into a dataset

Source: Internet
Author: User

Use C # to convert data from Excel into a dataset without the help of a third-party plug-in

<summary>////Excel Data Conversion DataSet///</summary>/<param name= "FilePath" > File full path </param&gt    ; <param name= "search" > Table name </param>//<returns></returns> private DataSet GetDataSet (Strin G fileName) {string strconn = "Provider=microsoft.ace.oledb.12.0;data source=" + FileName + "; Extended properties= ' Excel 12.0;      Hdr=yes;imex=1 '; ";      OleDbConnection objconn = null;      objconn = new OleDbConnection (strconn);      objConn.Open ();      DataSet ds = new DataSet ();      list<string> List = new List<string> {"Payment amount", "Pay duty", "Prepaid fee", "overdue", "to account Profit"};      list<string> List = new List<string> {};      DataTable dtsheetname = objconn.getoledbschematable (OleDbSchemaGuid.Tables, new object[] {null, NULL, NULL, "TABLE"}); foreach (DataRow dr in Dtsheetname.rows) {if (dr["table_name"]. ToString (). Contains ("$") &&!dr[2]. ToString (). EndsWith ("$")) {continue;       } string s = dr["table_name"].        ToString ();      List.add (s); try {for (int i = 0; i < List.count; i++) {ds.          Tables.add (List[i]);          String sheetname = List[i];          String strSQL = "SELECT * FROM [" + SheetName + "]";          OleDbDataAdapter odbccsvdataadapter = new OleDbDataAdapter (strSQL, objconn); DataTable dt = ds.          Tables[i];        Odbccsvdataadapter.fill (DT);      } return DS;      } catch (Exception ex) {return null;        } finally {objconn.close ();      Objconn.dispose (); }    }

The above mentioned is the whole content of this article, I hope you can like.

In addition to the Declaration, Running GuestArticles are original, reproduced please link to the form of the address of this article
C # converts data from Excel into a dataset

This address: http://www.paobuke.com/develop/c-develop/pbk23092.html






Related content convert any type of generic collection to an instance of SQLXML data format in C # How to choose how to implement XSL transformations using ArrayList, HashTable, List, dictionary arrays C # Several usages of using directives in C #
C # Method of stopping threading in C # A typical flaw for beginners in C # using the @ Declaration variable example (verbatim identifier) C # Summary of common methods of string class

C # converts data from Excel into a dataset

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.