当前位置:网站首页>Summary of SQL basic syntax for C #
Summary of SQL basic syntax for C #
2022-06-28 03:40:00 【Bright in snow】
「 Blog move 」 New address : Simple books
This article is currently used for Visual Studio 2015 Platform SQLite3 , Other uses will be summarized later .
1. Use Nuget add to SQLite library
stay Visual Studio 2015 in , choice : Tools -> NuGet Package manager -> Manage solutions NuGet Package
Search in this interface 「SQLite」, Choose to install one of them as needed SQLite library , It's better to be in the red box , A choice .
Then on the right side of the interface , Select the project you want to install to , After that, install it .
2. Common strategies
2.1 Catch exceptions
try
{
// Put the statements that operate on the database in try in
}
catch (Exception ex)
{
// Handle exceptions
}
2.2 Business and SQLite The code framework
// Use the following statement in conjunction with the specific SQL Just operate the statement
// notes : Do not actively control transactions , Every time you execute SQL The command will start the new transaction repeatedly ,
// Will be in SQL It takes a lot of time to operate . So there are a lot of insertions 、 Modify the operating
// when , Proactively starting a transaction saves a lot of time
var conn = new SQLiteConnection("Data Source = ./bitkyData.db; Version = 3; ");
conn.Open();
var trans = conn.BeginTransaction(); // Open transaction
var cmd = conn.CreateCommand();
try
{
// By manipulating the cmd, Use specific SQL Operation statement
}
catch (Exception)
{
trans.Rollback(); // Transaction rollback
// Perform specific exception handling
}
trans.Commit();// Transaction submission
conn.Close();// Connection is closed
3. Required code block
3.1 Necessary initialization operations
// Specify the address of the database , as well as SQLite Version number
SQLiteConnection conn = new SQLiteConnection("Data Source = ./bitkyData.db; Version = 3; ");
3.2 Insert the specified entry into the table
void insertData()
{
conn.Open();
var cmd = conn.CreateCommand();
cmd.CommandText = "INSERT INTO ElectrodeController(typeA,typeB,typeM) VALUES (1, 2, 3)";
cmd.ExecuteNonQuery();
conn.Close();
}
3.3 Set the query criteria , Query the contents of the specified entry
static void selectData()
{
conn.Open();
var cmd = conn.CreateCommand();
cmd.CommandText = "SELECT * FROM ElectrodeController where num > 45";
var reader = cmd.ExecuteReader();// Get the result set
if (reader.HasRows)
{
while (reader.Read())
{
Debug.WriteLine("ID: " + reader.GetInt32(0));
}
}
conn.Close();
}
3.4 Get the number of entries in the data table
static void getCount()
{
conn.Open();
var cmd = conn.CreateCommand();
cmd.CommandText = "SELECT COUNT(*) FROM ElectrodeController";
var scalar = cmd.ExecuteScalar();\\ Get the value of the first row and the first column in the result set
Debug.WriteLine("count: " + Convert.ToInt32(scalar));
conn.Close();
}
4. Reference material
边栏推荐
- INFO: HHH000397: Using…
- Redis搭建集群【简单】
- 2022 operation of simulated examination platform of special operation certificate examination question bank for safety management personnel of hazardous chemical business units
- Set drop-down options on Excel files
- nn. Parameter and torch nn. Init series of functions to initialize model parameters
- 在excel文件上设置下拉选项
- 基于 WPF 的酷炫 GUI 窗口的简易实现
- composition api在项目中的使用总结
- 荣耀v8 真机调试时不显示 Logcat 日志的解决办法
- Ten reasons for system performance failure
猜你喜欢
【PaddleDetection】ModuleNotFoundError: No module named ‘paddle‘
WebSocket(简单体验版)
可扩展存储系统(上)
2022 electrician (elementary) recurrent training question bank and online simulation examination
Necessary software tools in embedded software development
service实现类里面为何一直报红
大咖说·计算讲谈社|什么是东数西算要解决的核心问题?
matlab习题 —— 数据的基本处理
基于 LNMP 搭建个人网站的填坑之旅
__getitem__和__setitem__
随机推荐
Question bank and answers of special operation certificate for R1 quick opening pressure vessel operation in 2022
基于 WPF 的酷炫 GUI 窗口的简易实现
SSH框架的搭建(上)
xml 文件的读写
Tencent games released more than 40 products and projects, including 12 new games
Dataloader parameter collate_ Use of FN
Build your own website (17)
service实现类里面为何一直报红
启牛商学院赠送证券账户是真的吗?开户到底安不安全呢
力扣每日一题-第29天-219.存在重复元素Ⅱ
Use js programming questions [split] in Niuke
2022 safety officer-c certificate examination question bank simulated examination platform operation
matlab习题 —— 数据的基本处理
Huawei equipment WLAN basic service configuration command
Floating point and complex type of go data type (4)
Extensible database (Part 2)
数据库系列之MySQL中的执行计划
What is the difference between slice and array in go question bank 12?
Object类,以及__new__,__init__,__setattr__,__dict__
R1 Quick Open Pressure Vessel Operation Special Operation Certificate Examination Library and Answers in 2022