导入access到sqlite

//打开mdb数据库
    OleDbConnection mdbConn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:英汉字库.mdb");
    mdbConn.Open();
    OleDbDataAdapter mdbDa = new OleDbDataAdapter("select * from English",mdbConn);
    DataSet mdbDs = new DataSet();
    mdbDa.Fill(mdbDs,"English");
   

    //打开sqlite数据库
    SQLiteConnection sqliteConn = new SQLiteConnection("Data Source=database.db;New=True;Compress=True;Version=3");
    sqliteConn.Open();

    //建表
    SQLiteCommand sqliteCmd = sqliteConn.CreateCommand();
    sqliteCmd.CommandText = "CREATE table English (English varchar(50) Primary Key,Chinese varchar(50),Phonetic varchar(50))";
    sqliteCmd.ExecuteNonQuery();
   
    //插入数据
    SQLiteDataAdapter sqliteDa = new SQLiteDataAdapter("select * from English", sqliteConn);
    SQLiteCommandBuilder sqliteCb = new SQLiteCommandBuilder(sqliteDa);
   
    DataSet sqliteDs = new DataSet();
    sqliteDa.Fill(sqliteDs,"English");

    Console.WriteLine(sqliteDs.Tables["English"].Rows.Count);
    Console.WriteLine(mdbDs.Tables["English"].Rows.Count);
      
    foreach(DataRow dr in mdbDs.Tables["English"].Rows)
    {
     DataRow sqliteDr = sqliteDs.Tables["English"].NewRow();
     sqliteDr[0] = dr["english"];
     sqliteDr[1] = dr["chinese"];
     sqliteDr[2] = dr["phonetic"];
     sqliteDs.Tables["English"].Rows.Add(sqliteDr);
    }
    sqliteDa.Update(sqliteDs,"English");

posted @ 2009-01-02 15:48  遥望星空  阅读(1114)  评论(0编辑  收藏  举报