C# SQLite 简单封装

本文介绍如何在C#中进行SQLite数据库的操作,通过创建SQLiteHelper类进行简单封装,实现连接、查询、插入、更新和删除等基本功能,帮助开发者更高效地管理SQLite数据库。
摘要由CSDN通过智能技术生成

SQLiteHelper类

 1 using System;
2 using System.Configuration;
3 using System.Data;
4 using System.Data.SQLite;
5
6 namespace MyBlog.Data
7 {
8
9 /// <summary>
10 /// SQLiteHelper
11 /// </summary>
12 public class SQLiteHelper : System.IDisposable
13 {
14 private SQLiteConnection _SQLiteConn = null;
15 private SQLiteTransaction _SQLiteTrans = null;
16 private bool _IsRunTrans = false;
17 private string _SQLiteConnString = null;
18 private bool _disposed = false;
19 private bool _autocommit = false;
20 #region 构造/析构函数
21 /// <summary>
22 /// 初始化 SQLiteHelper
23
24 /// </summary>
25 public SQLiteHelper()
26 : this(ConfigurationManager.ConnectionStrings["SQLite"].ConnectionString)
27 {
28 }
29

 

  1 /// <summary>
2 /// 初始化 SQLiteHelper
3 /// </summary>
4 /// <param name="connectionstring">数据库连接字符串</param>
5 public SQLiteHelper(string connectionstring)
6 {
7 this._SQLiteConnString = connectionstring;
8 this._SQLiteConn = new SQLiteConnection(this._SQLiteConnString);
9 this._SQLiteConn.Commit += new SQLiteCommitHandler(_SQLiteConn_Commit);
10 this._SQLiteConn.RollBack += new EventHandler(_SQLiteConn_RollBack);
11 }
12
13 /// <summary>
14 /// SQLiteHelper 析构函数
15 /// </summary>
16 ~SQLiteHelper()
17 {
18 this.Dispose(false);
19 }
20
21 #endregion
22 #region 方法
23 /// <summary>
24 /// 打开数据库连接
25 /// </summary>
26 private void Open()
27 {
28 if (this._SQLiteConn.State == ConnectionState.Closed)
29 {
30 this._SQLiteConn.Open();
31 }
32
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值