Visual studio 2010及以上版本,连接SQLite数据库

1、在Sqlite开发站点下载SQLite的.exe安装包

 

Ctrl+F搜索这条语句:This is the only setup package that is capable of installing the design-time components for Visual Studio xxxx

找到对应的VS版本,注意一定要带bundle,集成了设计器;无论32位系统还是64位系统,似乎都要下载32位的(X86)

 

如下图:

 

 

下载后,安装,选择Full installation即可,

一路next,注意,请注意,如下红框的设计器一定要选上,否则,在Visual Studio中想添加新数据库时没有Sqlite这个选项,

Good luck,重启VS,在VS中可看到SQLite:

 

 2、连接数据库

添加连接--选择数据源:SQLite

如下:Database:.db文件所在文件位置(.db文件就是数据库)

 3、实现:点击按钮,在DataGridView显示数据库中的数据

(1)VS2010 在窗体中拉一个按钮和DataGridView,

 

(2)双击按钮添加事件

 

首先为项目添加引用

最上面添加:

 

   private void button1_Click(object sender, EventArgs e)
        {
            using (SQLiteConnection con = new SQLiteConnection(DATA_SOURCE))
            {
                con.Open();
                using (SQLiteCommand cmd = new SQLiteCommand())
                {
                    cmd.Connection = con;
                    cmd.CommandText = string.Format("select * from  test1");
                    int rows = cmd.ExecuteNonQuery();
                    SQLiteDataAdapter oraDA = new SQLiteDataAdapter(cmd);
                    DataSet ds = new DataSet();
                    oraDA.Fill(ds);
                    //con.Close();
                    DataTable dtbl = ds.Tables[0];
                    this.dataGridView1.DataSource = dtbl;
                }
            }





        }

DATA_SOURCE就是:"Data Source="C:/XX/XXX.db3;Pooling=true;FailIfMissing=false;Password=xxx";

 

 其他数据库基本都是如此,连接Oracle数据库方法:

 http://www.cnblogs.com/Donnnnnn/p/5955864.html

 

 

 

参考:

http://blog.csdn.net/missautumn/article/details/18567715

 posted on 2016-10-21 18:08  布鲁布鲁sky  阅读(13049)  评论(0编辑  收藏  举报