SQLite笔记
发布时间:2020-12-12 23:41:36 所属栏目:百科 来源:网络整理
导读:一、SQLite下载: http://www.sqlite.org/download.html (或在NuGet下载安装) 二、SQLite操作: 1、添加引用System.Data.SQLite,如安装目录在E:Program FilesSystem.Data.SQLite2010bin,则找到 System.Data.SQLite.dll 引用到当前项目中; using Sys
一、SQLite下载: http://www.sqlite.org/download.html (或在NuGet下载安装) 二、SQLite操作: 1、添加引用System.Data.SQLite,如安装目录在E:Program FilesSystem.Data.SQLite2010bin,则找到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,Reward) values ('山治',2000000000)"; command = new SQLiteCommand(sql,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 > 0; } } 3、效果显示: 三、资源收录 Sqlite全面学习(一、二、三) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐
- win x64下安装oracle 12c出现INS-30131报错的解决
- ruby – 使用sudo进行gem安装cocoapods
- amline_settings.xml 参数说明详解
- COCOS2D-X项目在XCODE没有IOS Simulator,无法仿
- 用 CocoaPods 安装 React Native
- c# – ASP.NET Web Control在第一次回发后显示旧
- c# – 使用ASP.NET Boilerplate将ValueObject存储
- vue实现单选和多选功能
- objective-c – 在EXC_BAD_ACCESS中代码= 1和代码
- 本地化 – 如何在ajaxToolkit中本地化今天的文本
热点阅读