当前位置: 移动技术网 > IT编程>开发语言>c# > C#中嵌入SQLite数据库的简单方法

C#中嵌入SQLite数据库的简单方法

2019年07月18日  | 移动技术网IT编程  | 我要评论
sqlite,是一款轻型的数据库,是遵守acid的关系型数据库管理系统,它包含在一个相对小的c库中。它是d.richardhipp建立的公有领域项目。它的设计目标是嵌入式的

sqlite,是一款轻型的数据库,是遵守acid的关系型数据库管理系统,它包含在一个相对小的c库中。它是d.richardhipp建立的公有领域项目。它的设计目标是嵌入式的,而且目前已经在很多嵌入式产品中使用了它,它占用资源非常的低,在嵌入式设备中,可能只需要几百k的内存就够了。它能够支持windows/linux/unix等等主流的操作系统,同时能够跟很多程序语言相结合,比如 tcl、c#、php、java等,还有odbc接口,同样比起mysql、postgresql这两款开源的世界著名数据库管理系统来讲,它的处理速度比他们都快。

sqlite第一个alpha版本诞生于2000年5月。 至2015年已经有15个年头,sqlite也迎来了一个版本 sqlite 3已经发布。

具体下载地址:

编写sqlite测试方法

引用命名空间:
using system.data.sqlite;
using system.data.sqlite.generic;
using system.data.common;
 
    /// <summary>
    ///【测试方法】 简答的测试sqlite数据库及表的创建过程
    /// </summary>
    [testmethod()]
    public void test()
    {
      string strconnectionstring = string.empty,/*sqlite连接字符串,刚开始没有,暂时留空*/
          strdatasource = @"d:\test.db";//sqlite数据库文件存放物理地址
      //用sqliteconnectionstringbuilder构建sqlite连接字符串
      system.data.sqlite.sqliteconnectionstringbuilder scbuilder = new sqliteconnectionstringbuilder();
      scbuilder.datasource = strdatasource;//sqlite数据库地址
      scbuilder.password = "123456";//密码
      strconnectionstring = scbuilder.tostring();
      using (sqliteconnection connection = new sqliteconnection(strconnectionstring))
      {
        //验证数据库文件是否存在
        if (system.io.file.exists(strdatasource) == false)
        {
          //创建数据库文件
          sqliteconnection.createfile(strdatasource);
        }
        //打开数据连接
        connection.open();
        //command
        sqlitecommand command = new sqlitecommand(connection);
        command.commandtext = "create table tb_user(id int,username varchar(60));insert into [tb_user](id,username) values(1,'a')";// "create table tb_user(id int,username varchar(60));";
        command.commandtype = system.data.commandtype.text;
        //执行sql
        int iresult = command.executenonquery();
        //可省略步骤=======关闭连接
        connection.close();
      }
    }

示意图:

以上所述就是本文的全部内容了,希望大家能够喜欢。

如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网