.NET中操作SQLite
C#操作SQLite Database
C#下SQLite操作驱动dll下载:System.Data.SQLite
C#使用SQLite步骤:
(1)新建一个project
(2)添加SQLite操作驱动dll引用
(3)使用API操作SQLite DataBase
using System;
using System.Data.SQLite; namespace SQLiteSamples
{
class Program
{
//数据库连接
SQLiteConnection m_dbConnection; static void Main(string[] args)
{
Program p = new Program();
} public Program()
{
createNewDatabase();
connectToDatabase();
createTable();
fillTable();
printHighscores();
} //创建一个空的数据库
void createNewDatabase()
{
SQLiteConnection.CreateFile("MyDatabase");
//默认生成的数据库文件和System.Data.SQLite.dll在同一路径下
}
//创建一个连接到指定数据库
void connectToDatabase()
{
m_dbConnection = new SQLiteConnection("Data Source=MyDatabase;Version=3;");
m_dbConnection.Open();
}
//在指定数据库中创建一个table
void createTable()
{
string sql = "create table highscores (name varchar(20), score int)";
SQLiteCommand command = new SQLiteCommand(sql, m_dbConnection);
command.ExecuteNonQuery();
}
//插入一些数据
void fillTable()
{
string sql = "insert into highscores (name, score) values ('Me', 3000)";
SQLiteCommand command = new SQLiteCommand(sql, m_dbConnection);
command.ExecuteNonQuery();
sql = "insert into highscores (name, score) values ('Myself', 6000)";
command = new SQLiteCommand(sql, m_dbConnection);
command.ExecuteNonQuery();
sql = "insert into highscores (name, score) values ('And I', 9001)";
command = new SQLiteCommand(sql, m_dbConnection);
command.ExecuteNonQuery();
}
//使用sql查询语句,并显示结果
void printHighscores()
{
string sql = "select * from highscores order by score desc";
SQLiteCommand command = new SQLiteCommand(sql, m_dbConnection);
SQLiteDataReader reader = command.ExecuteReader();
while (reader.Read())
Console.WriteLine("Name: " + reader["name"] + "\tScore: " + reader["score"]);
Console.ReadLine();
}
}
}
关于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
.NET中操作SQLite的更多相关文章
- Android中操作SQLite数据库
我又回到了安卓的学习当中,忙来忙去终于忙的差不多有时间做自己的事情了,这感觉实在是太棒了!!本来想写android的控件以及他们的监视器的,但是我查了查android的手册,基本上都能查到,但是查有些 ...
- 【SQLite】 C#中操作SQlite
简介 SQLite是轻量级数据库,具体的介绍请参考官网(SQLite官网).在WinForm的项目中需要采用独立的数据库访问,可在断网单机上使用,所以选择了SQLite! 使用 主要针对C#项目(Wi ...
- android中操作SQLite注意事项
调用rawQuery()后,需要调用Cursor的movToFirst(); public Cursor query(String sql, String[] args){ SQLiteDatabas ...
- 在项目中使用SQLite数据库小结
------------------------------------------------------------------------推荐: - VS2012 使用 1.0.84 版的库 - ...
- JDBC访问及操作SQLite数据库
SQLite 是一个开源的嵌入式关系数据库,其特点是高度便携.使用方便.结构紧凑.高效.可靠. 与其他数据库管理系统不同,SQLite 的安装和运行非常简单,在大多数情况下,只要确保SQLite的二进 ...
- Qt 操作SQLite数据库
项目中通常需要采用各种数据库(如 Qracle.SQL Server.MySQL等)来实现对数据的存储.查询等功能.下面讲解如何在 Qt 中操作 SQlite 数据库. 一.SQLite 介绍 Sql ...
- Qt-数据库操作SQLite
1 简介 参考视频:https://www.bilibili.com/video/BV1XW411x7NU?p=88 说明:本文对在Qt中操作SQLite做简要说明. SQLite:SQLite 是 ...
- 2014-08-01 ASP.NET中对SQLite数据库的操作——ADO.NET
今天是在吾索实习的第18天.我主要学习了如何在ASP.NET中对SQLite数据库的操作,其基本操作如下: 添加引用System.Data.SQLite.dll(PS:在网页里面任意找到适合的.NET ...
- UWP: 在 UWP 中使用 Entity Framework Core 操作 SQLite 数据库
在应用中使用 SQLite 数据库来存储数据是相当常见的.在 UWP 平台中要使用 SQLite,一般会使用 SQLite for Universal Windows Platform 和 SQLit ...
随机推荐
- Html.TextBoxFor三元判断
@Html.TextBoxFor(item => item.DiscountOW,(Model.TripType == "单程" || (Model.TripType == ...
- roscpp源码阅读
roscpp doxgen 这只是我摘取的一些主要代码 node_handle.cpp //NodeHandle的构造函数 void NodeHandle::construct(const std:: ...
- 1017. Queueing at Bank (25)
Suppose a bank has K windows open for service. There is a yellow line in front of the windows which ...
- Unable to create the store directory. (Exception from HRESULT: 0x80131468)
一个ASP.NET的程序,使用了MS ReportViewer报告控件,在用该控件导出生成Excel文件时,先是提示行不能超过65535. 这个是由于Excel2003的行限制的原因.由于修改成用Ex ...
- 关于C与C++的struct,union,enum用法差异
对着代码说话: #include <stdio.h> #include <stdlib.h> struct test { int abc; }; enum _enum {A,B ...
- 实现 iframe 子页面调用父页面中的js方法
父页面:index.html(使用iframe包含子页面child.html) [xhtml] view plaincopyprint? <html> <head> <s ...
- 3036: 绿豆蛙的归宿 - BZOJ
Description 随着新版百度空间的下线,Blog宠物绿豆蛙完成了它的使命,去寻找它新的归宿. 给出一个有向无环的连通图,起点为1终点为N,每条边都有一个长度.绿豆蛙从起点出发,走向终点.到达每 ...
- c++ std::string 用法
std::string用法总结 在平常工作中经常用到了string类,本人记忆了不好用到了的时候经常要去查询.在网上摘抄一下总结一下,为以后的查询方便: string类的构造函数: string(co ...
- IntelliJ IDEA 15 设置默认浏览器
一.设置系统默认浏览器 二.设置项目启动默认浏览器
- div均匀分布代码实例
多个div在同一行以相同间隔分布: 这样的布局效果使用非常的频繁,也就是让多个div在一行分布,并且div于div之间的间隙是一样的,多用在对于产品的展示之用,下面就介绍一下如何实现此中布局,代码实例 ...