zoukankan      html  css  js  c++  java
  • 使用.NET操作SQLLITE

    先下载ADO.NET2.0 Provider for SQLite。下载binaries zip版就可以了。下载完后解压缩,可以在bin目录下找到System.Data.SQLite.DLL。在vs2008中用Add Refrence功能把System.Data.SQLite.DLL加到工程里就可以了。运行下面代码试试:

     

      string datasource = "e:/tmp/test.db";

     

      System.Data.SQLite.SQLiteConnection.CreateFile(datasource);

     

      //连接数据库

     

      System.Data.SQLite.SQLiteConnection conn = new System.Data.SQLite.SQLiteConnection();

     

      System.Data.SQLite.SQLiteConnectionStringBuilder connstr = new System.Data.SQLite.SQLiteConnectionStringBuilder();

     

      connstr.DataSource = datasource;

     

      connstr.Password = "admin";//设置密码,SQLite ADO.NET实现了数据库密码保护

     

      conn.ConnectionString = connstr.ToString();

     

      conn.Open();

     

      //创建表

     

      System.Data.SQLite.SQLiteCommand cmd = new System.Data.SQLite.SQLiteCommand();

     

      string sql = "CREATE TABLE test(username varchar(20),password varchar(20))";

     

      cmd.CommandText = sql;

     

      cmd.Connection = conn;

     

      cmd.ExecuteNonQuery();

     

      //插入数据

     

      sql = "INSERT INTO test VALUES('a','b')";

     

      cmd.CommandText = sql;

     

      cmd.ExecuteNonQuery();

     

      //取出数据

     

      sql = "SELECT * FROM test";

     

      cmd.CommandText = sql;

     

      System.Data.SQLite.SQLiteDataReader reader = cmd.ExecuteReader();

     

      StringBuilder sb = new StringBuilder();

     

      while (reader.Read())

     

      {

     

      sb.Append("username:").Append(reader.GetString(0)).Append("\n")

     

      .Append("password:").Append(reader.GetString(1));

     

      }

     

      MessageBox.Show(sb.ToString());

  • 相关阅读:
    CentOS7使用firewalld打开关闭防火墙与端口
    SELinux: Could not downgrade policy file
    CentOS 安装 semanage 命令
    漏洞: RHSA2017:3075: wget security update
    CentOS7增加或修改SSH端口号
    gnl's not lao 道德经 英文版
    当代 IT 大牛排行榜
    当代 IT 大牛排行榜
    2008 年个人回忆与总结
    Patch2 for NetBeans IDE 6.5 Now Available
  • 原文地址:https://www.cnblogs.com/fjzhang/p/2615456.html
Copyright © 2011-2022 走看看