一、SQLite下载:

http://www.sqlite.org/download.html (或在NuGet下载安装)

二、SQLite操作:

  1、添加引用System.Data.SQLite,如安装目录在E:\Program Files\System.Data.SQLite\2010\bin,则找到System.Data.SQLite.dll引用到当前项目中;

using System.Data.SQLite;

  2、进行简单增删改查操作,语法跟sql server相差不大

 public class UseSQLIte
{
SQLiteConnection m_dbConnection;
public UseSQLIte()
{
createNewDatabase();
connectToDatabase();
createTable();
fillTable();
ShowInfo();
} //创建一个空的数据库
void createNewDatabase()
{
SQLiteConnection.CreateFile("SqliteDemo");
} //建立连接
bool connectToDatabase()
{
try
{
m_dbConnection = new SQLiteConnection("Data Source=SqliteDemo;Version=3;");
m_dbConnection.Open();
return true;
}
catch
{
return false;
}
} //创建表
void createTable()
{
string sql = "create table OnePiece(name VARCHAR(20), Reward BIGINT)";
SQLiteCommand command = new SQLiteCommand(sql, m_dbConnection);
command.ExecuteNonQuery();
} //插入数据
void fillTable()
{
string sql = "insert into OnePiece (name, Reward) values ('路飞', 5000000000)";
SQLiteCommand command = new SQLiteCommand(sql, m_dbConnection);
command.ExecuteNonQuery(); sql = "insert into OnePiece (name, Reward) values ('索隆', 3000000000)";
command = new SQLiteCommand(sql, m_dbConnection);
command.ExecuteNonQuery(); sql = "insert into OnePiece (name, Reward) values ('山治', 2000000000)";
command = new SQLiteCommand(sql, m_dbConnection);
command.ExecuteNonQuery(); sql = "insert into OnePiece (name, Reward) values ('乔巴', 100)";
command = new SQLiteCommand(sql, m_dbConnection);
command.ExecuteNonQuery();
} //查询语句,并显示结果
void ShowInfo()
{
string sql = "select * from OnePiece order by Reward desc";
SQLiteCommand command = new SQLiteCommand(sql, m_dbConnection);
using (SQLiteDataReader reader = command.ExecuteReader())
{
while (reader.Read())
Console.WriteLine("姓名: " + reader["name"] + "\t赏金: " + reader["Reward"]);
}
Console.ReadLine();
} bool check(string tableName)
{
string sql = "select count(*) from sqlite_master where type='table' and name ='" + tableName + "'";
SQLiteCommand command = new SQLiteCommand(sql, m_dbConnection);
int i = Convert.ToInt32(command.ExecuteScalar());
return i > ;
}
}

  3、效果显示:

三、资源收录

Sqlite全面学习(一、二、三)

SQLite笔记的更多相关文章

  1. 编写SQL语句操作数据库(慕课SQLite笔记)

    安卓常用数据存储方式之一SQLite学习及操作笔记 0.视频地址:http://www.imooc.com/video/3382 1.每个程序都有自己的数据库 默认情况下是各自互不干扰 1)创建一个数 ...

  2. Android中使用sqlite笔记

    1.实现SQLiteHelper来在android中使用SQLite.代码如下,来自android官网. public class FeedReaderDbHelper extends SQLiteO ...

  3. sqlite笔记(akaedu)

    1.创建sql表create table student(id integer primary key, name text, score integer): 2.插入一条记录insert into ...

  4. python之SQLite笔记

    sqlite3 打开文件并创建游标 conn = sqlite3.connect('adressbook.db')c = conn.cursor() 连接对象:sqlite3.connect('数据文 ...

  5. Ionic2学习笔记(8):Local Storage& SQLite

    作者:Grey 原文地址: http://www.cnblogs.com/greyzeng/p/5557947.html              Ionic2可以有两种方式来存储数据,Local S ...

  6. SQLite学习笔记(七)&&事务处理

    说到事务一定会提到ACID,所谓事务的原子性,一致性,隔离性和持久性.对于一个数据库而言,通常通过并发控制和故障恢复手段来保证事务在正常和异常情况下的ACID特性.sqlite也不例外,虽然简单,依然 ...

  7. Sqlite学习笔记(四)&&SQLite-WAL原理

    Sqlite学习笔记(三)&&WAL性能测试中列出了几种典型场景下WAL的性能数据,了解到WAL确实有性能优势,这篇文章将会详细分析WAL的原理,做到知其然,更要知其所以然. WAL是 ...

  8. Sqlite学习笔记(一)&&编译安装

    Sqlite简介 sqlite是一个开源的嵌入式文件数据库,sqlite以动态链接库的方式供应用程序调用,所有的数据库对象都存储在同一个文件中. sqlite动态库非常小,最新的3.8.11版本也只有 ...

  9. 安卓第四天笔记-Sqlite

    安卓第四天笔记-Sqlite 1.数据库的创建运行与更新 1.1.创建一个类继承SqliteOpenHelper 1.2.创建构造方法 /** * 数据库创建类 * @author 刘楠 * * 20 ...

随机推荐

  1. 51NOD 1220 约数之和 [杜教筛]

    1220 约数之和 题意:求\(\sum_{i=1}^n \sum_{j=1}^n \sigma_1(ij)​\) \[ \sigma_0(ij) = \sum_{x\mid i}\sum_{y\mi ...

  2. 【SSH框架】之Struts2系列(二)

    微信公众号:compassblog 欢迎关注.转发,互相学习,共同进步! 有任何问题,请后台留言联 1.Struts2常量配置 (1).Struts2默认常量配置文件路径,如下图: (2).Strut ...

  3. LeetCode - 520. Detect Capital

    Given a word, you need to judge whether the usage of capitals in it is right or not. We define the u ...

  4. 深入理解vue

    一 理解vue的核心理念 使用vue会让人感到身心愉悦,它同时具备angular和react的优点,轻量级,api简单,文档齐全,简单强大,麻雀虽小五脏俱全. 倘若用一句话来概括vue,那么我首先想到 ...

  5. 不受支持的URL Statue Code 1002

    1. 错误提示: Error description=Error Domain=NSURLErrorDomain Code=-1002 "unsupported URL" User ...

  6. PKUWC 2018游记

    PKUWC 2018游记 标签: Day\([-inf,0)\) 停课之后一直各种浪的飞起,考试rank20+,不搞颓但是学习很没有状态.还经常带着耳机被谢总抓了好几次,然后被拉过去谈话了好几次... ...

  7. [bzoj]2962序列操作

    [bzoj]2962序列操作 标签: 线段树 题目链接 题意 给你一串序列,要你维护三个操作: 1.区间加法 2.区间取相反数 3.区间内任意选k个数相乘的积 题解 第三个操作看起来一脸懵逼啊. 其实 ...

  8. 浅谈session,cookie,sessionStorage,localStorage的区别及应用场景

    浏览器的缓存机制提供了可以将用户数据存储在客户端上的方式,可以利用cookie,session等跟服务端进行数据交互. 一.cookie和session cookie和session都是用来跟踪浏览器 ...

  9. PHP不使用任何内置函数实现字符串翻转

    实现字符串翻转PHP本身自带一个函数就可以解决,strrev函数.这里不适用任何内置函数实现字符串翻转 案例一(纯字母): $str = 'abcdefghig k'; //假设测试的字符串/g与k之 ...

  10. Centos下安装php扩展sphinx

    官方地址:http://pecl.php.net/package/sphinx wget http://pecl.php.net/get/sphinx-1.3.3.tgz tar -zxvf sphi ...