sqlite帮助类
帮助类
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SQLite;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace 数据链接
{
public static class Sqllite
{
#region 样本
private static readonly string defaultConnectString = "Data Source=" + @"../../Properties/db_name.db";
#endregion
#region 变量
private static SQLiteConnection _con = null;
public static string _constr = "Data Source=" + @"../../Properties/db_name.db";
#endregion
#region 属性 public static string constr
{
get
{
if (_constr == null || _constr.Equals(String.Empty))
{
_constr = defaultConnectString;
}
return _constr;
}
set
{
_constr = value;
}
} /// <summary>
/// 获取或设置数据库连接对象
/// </summary>
public static SQLiteConnection Con
{
get
{ if (Sqllite._con == null)
{
Sqllite._con = new SQLiteConnection();
}
if (Sqllite._con.ConnectionString == null || Sqllite._con.ConnectionString.Equals(string.Empty))
{
Sqllite._con.ConnectionString = Sqllite.constr;
}
return Sqllite._con;
}
set
{
Sqllite._con = value;
}
}
#endregion /// <summary>
/// 获取数据表
/// </summary>
/// <param name="commandText">select命令</param>
/// <param name="param">参数表</param>
/// <returns></returns>
#region MyRegion
public static DataTable GetDataTable(string commandText, params SQLiteParameter[] param)
{
DataTable result = new DataTable();
try
{
using (SQLiteCommand cmd = new SQLiteCommand(commandText, Sqllite.Con))
{
if (param != null)
cmd.Parameters.AddRange(param);
try
{
SQLiteDataAdapter adapter = new SQLiteDataAdapter(cmd);
adapter.Fill(result);
}
catch (Exception ex)
{
result = null;
}
}
}
finally
{
if (Sqllite.Con.State != ConnectionState.Closed)
{
Sqllite.Con.Close();
}
}
return result;
}
#endregion /// <summary>
/// 执行不查询的数据库操作
/// </summary>
/// <param name="commandText">Oracle语句或存储过程名</param>
/// <param name="commandType">Oracle命令类型</param>
/// <param name="param">Oracle命令参数数组</param>
/// <returns>受影响的行数</returns>
#region MyRegion
public static int ExecuteNonQuery(string commandText, CommandType commandType, params SQLiteParameter[] param)
{
int result = ;
try
{
using (SQLiteCommand cmd = new SQLiteCommand(commandText, Sqllite.Con))
{
try
{
//cmd.CommandType = commandType;
if (param != null)
{
cmd.Parameters.AddRange(param);
}
Sqllite.Con.Open();
result = cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
result = -;
}
}
}
finally
{
if (Sqllite.Con.State != ConnectionState.Closed)
{
Sqllite.Con.Close();
}
}
return result;
}
#endregion }
}
调用
/// <summary>
/// sqlite增删改查
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button3_Click(object sender, EventArgs e)
{
DataTable dt = new DataTable();//DataTable接收传回的数据
dt = Sqllite.GetDataTable("select * from TBL_LANDSLIP;", null);//查询
// Sqllite.ExecuteNonQuery(@"INSERT INTO ZLCB01A (ZLCB01A005) VALUES('912')", CommandType.Text, null);//增加
// Sqllite.ExecuteNonQuery("delete from ZLCB01A WHERE ZLCB01A005='955'", CommandType.Text, null);//删除
// Sqllite.ExecuteNonQuery(@"update ZLCB01A SET ZLCB01A005='955' where ZLCB01A005='912'", CommandType.Text, null);//修改
}
sqlite帮助类的更多相关文章
- PHP基于PDO实现的SQLite操作类
<?php // sqlite分页类 class SqliteDB{ public function __construct(){ // 初始化数据库,并且连接数据库 数据库配置 $this-& ...
- Android Sqlite 工具类封装
鉴于经常使用 Sqlite 数据库做数据持久化处理,进行了一点封装,方便使用. 该封装类主要支持一下功能 支持多用户数据储存 支持 Sqlite数据库升级 支持传入 Sql 语句建表 支持 SQLit ...
- SQLite存储类(数据类型)
SQLite数据类型更普遍,采用动态类型系统. 说是数据类型,更像是存储类,如:INTEGER存储类就包含多种不同长度的整数数据类型 [INTEGER]带符号的整数类型 [REAL]浮点值,小数类型 ...
- c# Sqlite帮助类
最近有WPF做客户端,需要离线操作存储数据,在项目中考虑使用Sqlite嵌入式数据库,在网上找了不少资料,最终整理出一个公共的帮助类. Sqlite是一个非常小巧的数据库,基本上具备关系型数据库操作的 ...
- Sqlite 帮助类 SQLiteHelper
///源码下载地址:http://download.csdn.net/detail/kehaigang29/8836171 ///dll下载地址:http://download.csdn.net/de ...
- Android SQLITE 操作工具类
首先创建一个类 DatabaseHelper 继承SQLiteOpenHelper帮助类,定义数据库版本,数据库名称,创建表名. private static final int DATABASE_V ...
- php封装的sqlite操作类
sqlite在php中是默认安装的本地小型化数据库,类似于xml的小型数据库,但sqlite功能更强. sqlite.class.php文件: <?php class sqliteDB{ pri ...
- 封装Qt的SQLite接口类
还没测试完善.. #ifndef SQLITE_H #define SQLITE_H #include <QSqlDatabase> #include <QSqlQuery> ...
- SQLite帮助类SQlitehelper 实现对SQLite数据的增删改查
public class SQLiteHelper { public const string sConn = "Data Source=" + @"path" ...
随机推荐
- 树莓派Raspberry实践笔记—显示分辨率配置
转载:http://www.cnblogs.com/atsats/p/6607886.html 如果未接显示设备,使用VNC登录后,显示分辨率很小,应该是480p,导致使用很不方便. 这里通过修改/b ...
- 的aspnet_client文件夹
在早期,有一些asp.net组件是默认要调用(从客户端调用)服务器根(域名)下这个子目录里边的文件的. 不过如果你使用高版本的asp.net,那么全都从你的网站里调用了,因为asp.net有了更好地直 ...
- [WC2018]州区划分(状压,子集卷积)
[洛谷题面]https://www.luogu.org/problemnew/show/P4221 首先考虑判定一个子图是否合法: (1)连通:并查集判断即可. (2)没有欧拉回路:存在欧拉回路的条件 ...
- 图解jvm--(四)内存模型
内存模型 java 内存模型 很多人将[java 内存结构]与[java 内存模型]傻傻分不清,[java 内存模型]是 Java Memory Model(JMM)的意思. 简单的说,JMM 定义了 ...
- linux 镜像备份工具rsnyc
1.本地拷贝文件nohup rsync -avzh /data/wwwroot/xhprof/* /mnt/xhprof/ &2.更改文件夹名称mv /data/wwwroot/xhprof ...
- 一个简单的PHP文件下载方法 download
<?php /* * *@param function downloadFile 文件下载 * *@param string $filename 下载文件的路径(根目录下的绝对路径) * *@p ...
- 并发队列之ArrayBlockingQueue
上一篇我们说了并发队列中的LinkedBlockingQueue队列,这次我们看看ArrayBlockingQueue,看看名字,我们想象一下LinkedList和ArrayList的区别,我们可以知 ...
- JavaScript - Compiling Vs Transpiling
参考 https://blog.csdn.net/napolunyishi/article/details/20473799 https://www.stevefenton.co.uk/2012/11 ...
- Spring Boot Security JWT 整合实现前后端分离认证示例
前面两章节我们介绍了 Spring Boot Security 快速入门 和 Spring Boot JWT 快速入门,本章节使用 JWT 和 Spring Boot Security 构件一个前后端 ...
- 泛型DAO模型设计
aaarticlea/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAMCAgMCAgMDAwMEAwMEBQgFBQQEBQoHBwYIDAoMDAsKC