C # implements import and export of DB files

Source: Internet
Author: User
Tags open db file

1. Export of DB files

Private voidInsertdb (DataTable DT,stringFileName) {            Try            {                stringUserIDs =string.                Empty; string[] str = CcbUserName.Text.Split (',');  for(ints =0; s < Str. Length; s++) {UserIDs+ = GetUserId (Str[s]. Trim ()) +"',"; } userids= Userids.substring (0, Userids.length-1); if(string. IsNullOrEmpty (UserIDs)) {return; } Sqlitebaseclass SQLite=NewSqlitebaseclass (FileName); Try{sqlite.creatdatabase ();//Create a databaseSqlite. Sqliteconn =NewSystem.Data.SQLite.SQLiteConnection (SQLite).                    Strconntion); Sqlite.                    Sqliteconn.open (); //Create a tableSqlite.creatdatabasetable ("CREATE TABLE gpsinfo ([id] CHAR (+), [Gpstime] Datetime,[lon] Double,[lat] double,[speed] double,[direction] DOUBLE, [Sealevel] Double,[uploaded] int,[totallicheng] nvarchar ())"); Sqlite.creatdatabasetable ("CREATE TABLE sysparamters ([param] NVARCHAR (not Null,[pvalue] NVARCHAR ()"); Sqlite. strTableName="sysparamters"; //inserting GPS DataSqlite. strTableName ="Gpsinfo"; stringFields ="Id,gpstime,lon,lat,speed,direction,sealevel,totallicheng";//Field List                    stringValues =string. Empty;//Data ListUiprogressbar1.maximum =dt.                    Rows.Count;  for(inti =0; i < dt. Rows.Count; i++)                    {                        //convert array data to, split                        string[] STRs = dt. Rows[i]. Itemarray.select (w = w.tostring ()). toarray<string>(); //time type in db to convert, or read the Times wrongDateTime date = convert.todatetime (dt. rows[i]["Time"]); Values="'"+ strs[0] +"', '"+ Date. ToString ("s") +"', '"+string. Join ("', '", STRs,3,6) +"'"; Sqlite.insertfielddata (fields, values);//Inserting DataUiprogressbar1.value =i;                    System.Windows.Forms.Application.DoEvents (); }                }                Catch(Exception ex) {Throw NewException (ex.                Message); }                finally                {                    if(sqlite!=NULL&&sqlite. sqliteconn!=NULL) {SQLite.                    Sqliteconn.close (); }} msgboxshow.showinformation ("Export Success! "); }            Catch(Exception ex) {msgboxshow.showwarning ("Export Error:"+Ex.            Message); }        }

2. Import of DB files

//Get DB data
        private void Getdbdata (object sender, Waitwindoweventargs e) {try {i F (E.arguments.count > 0) {//Create SQLite operation Sqlitebaseclass SQLite = New Sqlitebaseclass (E.arguments[0].                    ToString ()); Sqlite. Sqliteconn = new System.Data.SQLite.SQLiteConnection (SQLite.                    Strconntion); Sqlite.                    Sqliteconn.open (); Query format is correct string Strgps = "Select Id,gpstime,lon,lat,speed,direction,totallicheng,sealevel from Gpsinf                    o Limit 1 ";                    String Strsys = "Select Param,pvalue from Sysparamters";                    DataSet Gpsset = Sqlite.getdatasetquerycontsql (STRGPS);                    DataSet Sysset = Sqlite.getdatasetquerycontsql (Strsys); if (Gpsset = = NULL | | Sysset = = NULL | | Gpsset.tables[0]. Rows.Count <= 0) {msgboxshow.showinformation ("DB file format error or no data present");                    Return }//Get data string strgpsinfo = "Select ID as Inspector, gpstime as time, Lon as longitude, lat as latitude, sp                     Eed as speed, direction as direction, "+" Totallicheng as total mileage, sealevel as elevation from Gpsinfo ORDER by Gpstime "; DataTable Gpsinfodt = Sqlite.getdatasetquerycontsql (strgpsinfo).                    Tables[0];                Calculate total Mileage E.result = Calculatetotallicheng (Gpsinfodt); }} catch (Exception ex) {msgboxshow.showwarning ("Open db File Error:" + ex.            Message); }        }

C # implements import and export capabilities for DB files

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.