XLS data import into SQLite database

Source: Internet
Author: User
Tags sqlite database

Protectedvoid Btn_ok_click (Object sender,EventArgs e) {try {String X=txtpath. Text;DataSet ds = GetConnect (x);DataTable xdatatable = ds. Tables[0];for (int i = 0; i < XDataTable.Rows.Count; i++) {var Voucherscode = (xdatatable.rows[i][0] +""). Substring (1). Trim ();var startime =Convert.todatetime (Xdatatable.rows[i][1]);var endtime =Convert.todatetime (xdatatable.rows[i][2]);var conversionproduct = Xdatatable.rows[i][3];var status = 0;Sqlitehelper.executenonquery (Insert into [vouchers] (Voucherscode,startime,endtime,conversionproduct,status) VALUES (' "+ Voucherscode +"', '" + Startime +"', '" + Endtime +"', '" + conversionproduct +"', '" + Status +"‘)"); } lblshow. InnerText ="Import succeeded!"        "; }CatchException ex) {lblshow. InnerText ="Import failed!"        "; }    }///<summary>///Export data from an Excel table to myDataSet///</summary>PublicStaticDataSet GetConnect (String FilePath) {DataSet myDataSet =NewDataSet ();String Strcon ="Provider=Microsoft.Jet.OLEDB.4.0; Data source= "+ FilePath +"; Extended properties=\ "Excel 8.0; Hdr=yes; Imex=1;\ "";if (Path.getextension (FilePath). ToLower () = =". xlsx") Strcon ="Provider=microsoft.ace.oledb.12.0;data source=" + FilePath +"; Extended properties= ' Excel 12.0; Hdr=yes;imex=1 ' ";OleDbConnection myconn =NewOleDbConnection (Strcon);Conditional Query Excel tableString strcom ="SELECT * FROM [sheet1$]"; MyConn.Open ();//Open Data link to get a data set OleDbDataAdapter mycommand = new OleDbDataAdapter (strcom, myconn);        //Create a DataSet object //Get your own DataSet object Mycommand.fill (myDataSet, "[sheet1$]");        //Close this data link myconn.close ();    return mydataset; }

XLS data import into SQLite database

Related Article

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.