帮助类

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. 杭电 1772 cake

    Cake Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  2. Lora、zigbee比较

    一 lora 主要频段:470MHz,亚洲其他地区主要是902-928MHz,欧洲主要是868MHz,美洲主要是915mHz lora优点: 通讯距离远(适合半径500m~2km,通信距离大于7000 ...

  3. linux文件或目录属性

    wc(word count)命令的功能:统计指定文件的字节数.字数.行数.,并将统计结果显示输出 命令参数: -c 只显示字节数 -l    只显示行数 -w 只显示字数 od命令:查看二进制文件信息 ...

  4. 测试者出的APP测试面试题

    测试者出的APP测试面试题 一.开场问题:(自由发挥) 1.请自我介绍一下: 2.为什么离开上一个公司呢? 3.做测试多久了?以前做过哪些项目?你们以前测试的流程是怎样的?用过哪些测试工具? 4.你觉 ...

  5. SpringBoot yml文件语法

    SpringBoot提供了大量的默认配置,如果要修改默认配置,需要在配置文件中修改. SpringBoot默认会加载resource下的配置文件: application*.yml applicati ...

  6. Oracle忘记密码怎么办?

    1.打开cmd,输入sqlplus /nolog,回车:输入“conn / as sysdba”;输入“alter user sys identified by 新密码”,注意:新密码最好以字母开头, ...

  7. python pandas模块简单使用(读取excel为例)

    第一步:模块安装 pip install pandas 第二步:使用(单个工作表为例) 说明:如果有多个工作表,那么只要指定sheetname=索引,(第一个工作表为0,第二个工作表为1,以此类推) ...

  8. vue element 时间选择器设置禁用日期

    在 el-date-picker 组件中有一个 picker-options 属性 disabledDate 可以设置日期的可选范围 <el-date-picker v-model=" ...

  9. ipmitool命令

    1.remote access control powerIpmitool -I lanplus -H 192.168.0.10 -U username -P Password chassis pow ...

  10. Vue——解决报错 Computed property "****" was assigned to but it has no setter.

    在最近的项目中遇到了如下的警告信息: [Vue warn]: Computed property " currentStep" was assigned to but it has ...