博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
C#使用SQLite
阅读量:4683 次
发布时间:2019-06-09

本文共 2873 字,大约阅读时间需要 9 分钟。

SQLite介绍

SQLite读[sk'laɪt]

SQLite is a software library that implements a self-contained, serverless, zero-configuration, transactional SQL database engine.

SQLite是一个开源、免费的小型RDBMS(关系型数据库),能独立运行、无服务器、零配置、支持事物,用C实现,内存占用较小,支持绝大数的SQL92标准。

SQLite数据库官方主页:http://www.sqlite.org/index.html

C#操作SQLite Database

C#下SQLite操作驱动dll下载:

C#使用SQLite步骤:

(1)新建一个project

(2)添加SQLite操作驱动System.Data.SQLite.dll引用

(3)使用API操作SQLite DataBase

using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using System.Data.SQLite;using System.IO;namespace SQLiteDemo1{    public partial class Form1 : Form    {        public Form1()        {            InitializeComponent();        }        private void button1_Click(object sender, EventArgs e)        {            string datasource = Application.StartupPath + @"\test.db";            bool isExist = File.Exists(datasource);            if (!isExist)            {                //创建数据库文件                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();            cmd.Connection = conn;            string sql = "";            if (!isExist)            {                //创建数据库文件                sql = "CREATE TABLE test(username varchar(20),password varchar(20))";                cmd.CommandText = sql;                cmd.ExecuteNonQuery();            }            //插入数据            sql = "INSERT INTO test VALUES('name_ludongbao','pwd_ludongbao')";            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)).Append("\n");            }            MessageBox.Show(sb.ToString());        }    }}

关于SQLite的connection string说明:http://www.connectionstrings.com/sqlite/

SQLite GUI客户端列表:http://www.sqlite.org/cvstrac/wiki?p=ManagementTools

SQLite Administrator下载地址:http://download.orbmu2k.de/files/sqliteadmin.zip

转载于:https://www.cnblogs.com/kylin2016/p/5807085.html

你可能感兴趣的文章
python会缓存小的整数和短小的字符
查看>>
格网与四叉树索引
查看>>
多张照片拍摄、图片浏览
查看>>
html(5) css
查看>>
Azure Web连接到Azure MySql Db
查看>>
Linux shell 命令判断执行语法 ; , && , ||
查看>>
vim代码格式化插件clang-format
查看>>
RTP Payload Format for Transport of MPEG-4 Elementary Streams over http
查看>>
Java环境变量设置
查看>>
【JBPM4】判断节点decision 方法3 handler
查看>>
filter 过滤器(监听)
查看>>
c语言基础知识要点
查看>>
node启动时, listen EADDRINUSE 报错;
查看>>
杭电3466————DP之01背包(对状态转移方程的更新理解)
查看>>
kafka中的消费组
查看>>
python--注释
查看>>
前端资源链接 ...
查看>>
yum install ntp 报错:Error: Package: ntp-4.2.6p5-25.el7.centos.2.x86_64 (base)
查看>>
leetcode-Single Number-136
查看>>
CF715C Digit Tree
查看>>