帮助类

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帮助类的更多相关文章

  1. PHP基于PDO实现的SQLite操作类

    <?php // sqlite分页类 class SqliteDB{ public function __construct(){ // 初始化数据库,并且连接数据库 数据库配置 $this-& ...

  2. Android Sqlite 工具类封装

    鉴于经常使用 Sqlite 数据库做数据持久化处理,进行了一点封装,方便使用. 该封装类主要支持一下功能 支持多用户数据储存 支持 Sqlite数据库升级 支持传入 Sql 语句建表 支持 SQLit ...

  3. SQLite存储类(数据类型)

    SQLite数据类型更普遍,采用动态类型系统. 说是数据类型,更像是存储类,如:INTEGER存储类就包含多种不同长度的整数数据类型 [INTEGER]带符号的整数类型 [REAL]浮点值,小数类型 ...

  4. c# Sqlite帮助类

    最近有WPF做客户端,需要离线操作存储数据,在项目中考虑使用Sqlite嵌入式数据库,在网上找了不少资料,最终整理出一个公共的帮助类. Sqlite是一个非常小巧的数据库,基本上具备关系型数据库操作的 ...

  5. Sqlite 帮助类 SQLiteHelper

    ///源码下载地址:http://download.csdn.net/detail/kehaigang29/8836171 ///dll下载地址:http://download.csdn.net/de ...

  6. Android SQLITE 操作工具类

    首先创建一个类 DatabaseHelper 继承SQLiteOpenHelper帮助类,定义数据库版本,数据库名称,创建表名. private static final int DATABASE_V ...

  7. php封装的sqlite操作类

    sqlite在php中是默认安装的本地小型化数据库,类似于xml的小型数据库,但sqlite功能更强. sqlite.class.php文件: <?php class sqliteDB{ pri ...

  8. 封装Qt的SQLite接口类

    还没测试完善.. #ifndef SQLITE_H #define SQLITE_H #include <QSqlDatabase> #include <QSqlQuery> ...

  9. SQLite帮助类SQlitehelper 实现对SQLite数据的增删改查

    public class SQLiteHelper { public const string sConn = "Data Source=" + @"path" ...

随机推荐

  1. 树莓派Raspberry实践笔记—显示分辨率配置

    转载:http://www.cnblogs.com/atsats/p/6607886.html 如果未接显示设备,使用VNC登录后,显示分辨率很小,应该是480p,导致使用很不方便. 这里通过修改/b ...

  2. 重新梳理IT知识之java-01语法(一)

    标识符的命名规范 包名:xxxyyyzzz 类名.接口名:XxxYyyZzz (大驼峰) 变量名.方法名:xxxYyyZzz 常量名:XXX_YYY_ZZZ //**************强制类型转 ...

  3. office 格式定义

    在做项目中,碰到如题的问题.比如要将居民的信息导出到excel中,居民的身份证号码因为长度过长(大于10位),excel会自动的将过长的数字串转换成 科学计数法.现在网上找到解决方案之一: (在数字串 ...

  4. IIS7和IIS8环境下 ThinkPHP专用URL Rewrite伪静态规则

      这是适用于IIS7,IIS7.5,IIS8.0及以上的ThinkPHP的伪静态规则,把以下代码保存成web.config文件,放到FTP的web目录内即可. <?xml version=&q ...

  5. FastStone Capture 截图工具

    主要功能介绍 截屏 包括了全屏截取,当前活动窗口截取,截取选定区域,多边形截取和截取滚动页面等,基本上常用的都有了.特别是滚动截取,许多朋友为了这个功能,不惜安装各种重量级的截屏软件,甚至四处下载各种 ...

  6. 工具 - VS Code

    杂项 1. 主题 brackets light pro, One Monokai theme 2. directory tree indent guidelines, directory vertic ...

  7. 如何安装部署和优化Tomcat?(Tomcat部署和优化与压测,虚拟主机配置,Tomcat处理请求的过程)

    文章目录 前言 一:Tomcat安装部署 1.1:Tomcat简介 1.2:Tomcat核心组件 1.3:Tomcat处理请求的过程 1.3.1:请求过程基本解释 1.3.2:请求过程详细解释 1.4 ...

  8. 信息论相关概念:熵 交叉熵 KL散度 JS散度

    目录 机器学习基础--信息论相关概念总结以及理解 1. 信息量(熵) 2. KL散度 3. 交叉熵 4. JS散度 机器学习基础--信息论相关概念总结以及理解 摘要: 熵(entropy).KL 散度 ...

  9. javascript入门教程01

    1.javascript中变量的声明和赋值的三种方式 (1)先声明后赋值 var width; width=5; (2)同时声明和赋值变量 var width=5; var x,y,z=10; (3) ...

  10. 吴裕雄--天生自然TensorFlow2教程:全连接层

    out = f(X@W + b) out = relut(X@W + b) import tensorflow as tf x = tf.random.normal([4, 784]) net = t ...