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" ...
随机推荐
- Cisco无线mDNS
1.mDNS介绍 两个协议:mDNS和Bonjour mDNS: mDNS(Multicast DNS):主要实现了在没有传统DNS Server的情况下使用LAN内的主机实现相互发现和通信. 使用U ...
- Jmeter_Http默认请求值
1.线程组->配置原件->Http请求默认值 2.作用:几个Http 请求参数都是重复的数据 3.优先级:Http请求默认值和单个Http请求数值,使用单个Http请求数值为主 举例如下: ...
- shell脚本部署apache并能通过浏览器访问!
第一步:导入httpd-2.2.17.tar包 第二步:创建一个test.sh文件(可在/root下) 第三步编写shell脚本 > 会重写文件,如果文件里面有内容会覆盖 >>这个是 ...
- paramiko linux pip18.1
Collecting paramiko Downloading https://files.pythonhosted.org/packages/cf/ae/94e70d49044ccc234bfdba ...
- 「AHOI2014/JSOI2014」支线剧情
「AHOI2014/JSOI2014」支线剧情 传送门 上下界网络流. 以 \(1\) 号节点为源点 \(s\) ,新建一个汇点 \(t\),如果 \(u\) 能到 \(v\),那么连边 \(u \t ...
- C/C++网络编程5——实现基于TCP的服务器端/客户端2
三次握手过程详解: 1:客户端的协议栈向服务器端发送SYN包,并告诉服务器端当前放送序号为j,客户端进入SYNC_SEND状态. 2:服务器端的协议栈收到这个包以后,和客户端进行ACK应答,应答值为j ...
- 在javaweb中从servlet端向jsp端传递数据的方法
1.servlet端: request.setAttribute("student", student)://向请求域中添加名称为student,内容为student中内容的数据( ...
- python 的参数总结
一.形参和实参 函数参数的作用是传递数据给函数使用 在使用的过程中,参数有两种形式:形式参数和实际参数 形参: 定义函数的参数 实参: 调用函数时的参数 根据实际参数类型不同,将实际参数传递给形参的方 ...
- np.ndarray与PIL.Image对象相互转换
Image对象有crop功能,也就是图像切割功能,但是使用opencv读取图像的时候,图像转换为了np.adarray类型,该类型无法使用crop功能,需要进行类型转换,所以使用下面的转换方式进行转换 ...
- 树莓派安装nextcloud、Seafile
参考博文:http://bbs.eeworld.com.cn/thread-505579-1-1.html http://blog.sina.com.cn/s/blog_6f55d8210102xia ...