当前位置:网站首页>C # use SQLite
C # use SQLite
2022-07-24 22:06:00 【flysh05】
SQLite Is a lightweight embedded database in process , Its database is a file , Self sufficiency has been achieved 、 There is no server 、 Zero configuration 、 transactional SQL Database engine . It is a zero-configuration database , That's what it's all about SQLite The biggest difference from other databases :SQLite It does not need to be configured in the system , Directly available . And SQLite It's not an independent process , You can connect statically or dynamically according to your application requirements .SQLite You can directly access its storage files .
1. install :System.Data.SQLite Components

2. Create data table
First, you need to create a table in the data , To add data , Only when there is data can the query be demonstrated , Modification and deletion .
Create a Person surface .
string dbfile = @"URI=file:sql.db";
SQLiteConnection cnn = new SQLiteConnection(dbfile);
cnn.Open();
string sql = "Create table Person (Id integer primary key, Name text);";
SQLiteCommand cmd = new SQLiteCommand(sql, cnn);
cmd.ExecuteNonQuery();
cnn.Close();
3. Add row data
string dbfile = @"URI=file:sql.db";
SQLiteConnection cnn = new SQLiteConnection(dbfile);
cnn.Open();
string sql = "insert into Person (Id , Name) values(1,'Mike');";
SQLiteCommand cmd = new SQLiteCommand(sql, cnn);
cmd.ExecuteNonQuery();
cnn.Close();
Console.WriteLine("Insert row OK");
4. Query data
string dbfile = @"URI=file:sql.db";
SQLiteConnection cnn = new SQLiteConnection(dbfile);
cnn.Open();
string sql = "Select * From Person";
SQLiteCommand cmd = new SQLiteCommand(sql, cnn);
SQLiteDataReader reader = cmd.ExecuteReader();
while(reader.Read())
{
Console.WriteLine($"{
reader.GetInt32(0)} {
reader.GetString(1)} ");
}
reader.Close();
cnn.Close();
5. Update data
string dbfile = @"URI=file:sql.db";
SQLiteConnection cnn = new SQLiteConnection(dbfile);
cnn.Open();
string sql = "update Person set Name='Jim jones' where id=1;";
SQLiteCommand cmd = new SQLiteCommand(sql, cnn);
cmd.ExecuteNonQuery();
cnn.Close();
Console.WriteLine("Update row OK");
6. Delete data
string dbfile = @"URI=file:sql.db";
SQLiteConnection cnn = new SQLiteConnection(dbfile);
cnn.Open();
string sql = "delete from Person where id=3;";
SQLiteCommand cmd = new SQLiteCommand(sql, cnn);
cmd.ExecuteNonQuery();
cnn.Close();
Console.WriteLine("Delete row OK");
Basic data operation is realized , Additions and deletions . It can be used with a little modification in daily application .
边栏推荐
- Drawing library Matplotlib styles and styles
- Documentary of the second senior brother
- Day10: declarative transaction control
- Composability and Recursion in snarkyJS
- PR 2022 22.5 Chinese version
- What problems should be paid attention to when using a database without public ip: port?
- Go+语言
- RISC0:Towards a Unified Compilation Framework for Zero Knowledge
- Win10 solution Base64
- Shallow copy deep copy
猜你喜欢

Everything about database, database and table is here

Documentary of the second senior brother

Maixll dock QR code recognition

MySQL forced indexing

Sqlserver BCP parameter interpretation, character format selection and fault handling summary

2022 Tsinghua summer school notes L2_ 1 basic composition of neural network

MQ release confirmation

工程项目管理软件排名

Ue5 reports an error using the plug-in quixel Bridge

Thread pool learning
随机推荐
2022 Tsinghua summer school notes L2_ 2 basic introduction of CNN and RNN
C# 回看委托与事件
一键编译安装redis6.2.4
Low code that democratizes software development
Esp32485 air temperature and humidity test
Redefine analysis - release of eventbridge real-time event analysis platform
What is a self built database on ECs?
Apipost签约中国电信!携手加速企业数字化变革
It's the same type of question as just K above
Kubernetes v1.24 is deployed based on containerd
Drawing library matplotlibmatplotlib quick start
OSI architecture and protocols at all levels
2022 Tsinghua summer school notes L1_ NLP and bigmodel Foundation
【ICML2022】气候变化与机器学习:机遇、挑战与考虑,121页ppt
My love lesson 2 - remove webpage pop-up
做好项目管理的10个关键点和5大措施
【Pyspark基础】行转列和列转行(超多列时)
微机原理:CPU架构详解
“IRuntime”: 未声明的标识符
Cell special issue | application and future prediction of AI in protein structure, precision medicine, antibody therapy [review]