VS2010连接SQLite数据库

 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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值