Copy table from the musql to sqlite database

First, mysql connector/net, download it from here: http://mirror.mirimar.net/mysql/Downloads/Connector-Net/mysql-connector-net-6.1.3.zip

And for Sqlite connector, download it from here:

http://nchc.dl.sourceforge.net/project/sqlite-dotnet2/SQLite%20for%20ADO.NET%202.0/1.0.65.0/SQLite-1.0.65.0-setup.exe

Now in your project  add reference to this dll file

·         C:\Program Files\MySQL\MySQL Connector Net 6.1.3\Assemblies\MySql.Data.dll

·         C:\Program Files\SQLite.NET\bin\System.Data.SQLite.dll

 

And now in your form add this

using MySql.Data.MySqlClient;

using System.Data.SQLite;

Finally add the following code to your application:

 

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

using MySql.Data.MySqlClient;

using System.Data.SQLite;

 

 

namespace WindowsApplication23

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

        }

 

        private void button1_Click(object sender, EventArgs e)

        {

            string MyConString = "SERVER=localhost;DATABASE=mysql;UID=root;PASSWORD=123456;";

            string query="";

            MySqlConnection connection = new MySqlConnection(MyConString);

            MySqlCommand command = new MySqlCommand("select id,name from users", connection);

            MySqlDataReader Reader;

             

            SQLiteConnection conn = new SQLiteConnection("Data Source=E:\\contacts.db;Version=3;");

            

 

            connection.Open();

            conn.Open();

 

            Reader = command.ExecuteReader();

            int i = 0;

            while (Reader.Read())

            {

                query = "insert into users(id,name) values(" + Reader.GetValue(0).ToString() + ",'" + Reader.GetValue(1).ToString() + "')";

                SQLiteCommand cmd = new SQLiteCommand(query, conn);

                 i=i+cmd.ExecuteNonQuery();

 

            }

            MessageBox.Show(i.ToString()+" record transferred to MySql TO Sqlite database");

            connection.Close();

            conn.Close();

 

        }

    }

    }

 

Ebook Download
View all
Learn
View all