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