appsettings

<configuration>
    <appSettings>
        <add key="ConnectionString" value="Data Source=.;Initial Catalog=Test;User Id=sa;Password=123;" />

</appSettings>
</configuration>

connectionStrings

<connectionStrings>
<add name="ConnectionString" connectionString="Data Source=.;Initial Catalog=Test;Persist Security Info=True;User ID=sa;Password=123;" providerName="System.Data.SqlClient"/>
  </connectionStrings>

APP.CONGIG文件

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<!--<connectionStrings>

<add connectionString="data sourse = cater.db;version =3;" name="constr"/> --><!--连接字符串配置文件,字符串名字--><!--
</connectionStrings>-->

<appSettings>

<add key="constr" value=" data source=cater.db;version =3;"/>
</appSettings>

<!--<connectionStrings >

<add name="constr" connectionString="data source =cater.db;version =3;"/>
</connectionStrings>-->

</configuration>

代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SQLite;
using System.Data;
using System.Configuration;

namespace restaurant.DAL
{
public class SQLiteHelper
{ //连接字符串
private static readonly string str = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
string dd = ConfigurationManager.AppSettings["constr"].ToString();

/// <summary>
/// 增删改
/// </summary>
/// <param name="sql">sql语句</param>
/// <param name="param">参数</param>
/// <returns>返回受影响的行数</returns>
public static int ExecuteNonQuery(string sql, params SQLiteParameter[] param)
{
using (SQLiteConnection conn = new SQLiteConnection(str))
{
using (SQLiteCommand cmd = new SQLiteCommand(sql, conn))
{
conn.Open();
if (param != null)
{
cmd.Parameters.AddRange(param);
}
return cmd.ExecuteNonQuery();
}
}
}
/// <summary>
/// 查询
/// </summary>
/// <param name="sql">sql 语句</param>
/// <param name="param">参数</param>
/// <returns>返回 首行首列</returns>
public static object ExecuteScale(string sql, params SQLiteParameter[] param)
{
using (SQLiteConnection conn = new SQLiteConnection(str))
{
using (SQLiteCommand cmd = new SQLiteCommand(sql, conn))
{
conn.Open();
if (param != null)
{
cmd.Parameters.AddRange(param);
}
return cmd.ExecuteScalar();
}
}
}

/// <summary>
///多行查询
/// </summary>
/// <param name="sql">sql语句</param>
/// <param name="param">参数</param>
/// <returns>ExecuteReader</returns>
public static SQLiteDataReader ExecueDataReader(string sql, params SQLiteParameter[] param)
{
SQLiteConnection conn = new SQLiteConnection(str);
using (SQLiteCommand cmd = new SQLiteCommand(sql, conn))
{
if (param != null)
{
cmd.Parameters.AddRange(param);
}
try
{
conn.Open();
return cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection);
}
catch (Exception ex)
{
conn.Close();
cmd.Dispose();
throw ex;
}
}
}
/// <summary>
/// 查询多行数据
/// </summary>
/// <param name="sql">sql语句</param>
/// <param name="param">sql参数</param>
/// <returns>一个表</returns>
public static DataTable ExecuteTable(string sql, params SQLiteParameter[] param)
{
DataTable dt = new DataTable();
using (SQLiteDataAdapter sda = new SQLiteDataAdapter(sql, str))
{
if (param != null)
{
sda.SelectCommand.Parameters.AddRange(param);
}
sda.Fill(dt);
}
return dt;
}
}
}

sqlitehelper封装的更多相关文章

  1. [C#] 简单的 Helper 封装 -- SQLiteHelper

    using System; using System.Data; using System.Data.SQLite; namespace SqliteConsoleApp { /// <summ ...

  2. 封装SqliteHelper类--Sqlite数据库

    using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threa ...

  3. Swift版的SQLiteHelper

    SQLiteHelper 创建SQLiteHelper类 /// SQLite数据库处理帮助类 /// /// 此类中封装了关于SQLite数据库处理的业务函数 class SQLiteHelper ...

  4. C#对SQLite、Access数据库操作的封装,很好用的~

    1.对SQLite的封装: using System; using System.Collections.Generic; using System.Linq; using System.Text; ...

  5. [C#] 改进SqliteHelper, 减少拼接SQL语句

    说明:开始几个是基本的方法,后面稍微封装了下 public class SqliteHelper { //连接字符串 private static readonly string str = Conf ...

  6. [C#] 简单的 Helper 封装 -- RegularExpressionHelper

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  7. iOS开发之App间账号共享与SDK封装

    上篇博客<iOS逆向工程之KeyChain与Snoop-it>中已经提到了,App间的数据共享可以使用KeyChian来实现.本篇博客就实战一下呢.开门见山,本篇博客会封装一个登录用的SD ...

  8. Ajax实现原理,代码封装

    都知道实现页面的异步操作需要使用Ajax,那么Ajax到是怎么实现异步操作的呢? 首先需要认识一个对象 --> XMLHttpRequest 对象 --> Ajax的核心.它有许多的属性和 ...

  9. 用C语言封装OC对象(耐心阅读,非常重要)

    用C语言封装OC对象(耐心阅读,非常重要) 本文的主要内容来自这里 前言 做iOS开发的朋友,对OC肯定非常了解,那么大家有没有想过OC中NSInteger,NSObject,NSString这些对象 ...

随机推荐

  1. Android 优秀UI控件 ---- FlowingDrawer

    1,前天在git上看到了一个不错的控件 ,最近两天项目也没有那么赶了,就抽时间来写写代码,锻炼一下手感,先看一下效果吧. 2 整体来看 ,主要是有两块来实现的,①主界面的RecyclerView ,② ...

  2. 夺命雷公狗---DEDECMS----7dedecms目录结构

    我们dedecms的目录结构其实只需要一张图即可明了了,如下图所示:

  3. [ThinkPHP] 输出、模型的使用

    # # ThinkPHP 3.1.2 输出和模型使用 # 讲师:赵桐正 微博:http://weibo.com/zhaotongzheng   本节课大纲: 一.ThinkPHP 3 的输出      ...

  4. 关于基于.NET Framework的网络通信程序底层扫盲

    引自<三维游戏引擎的设计与实现>书中9.3节:          如果服务端在.Net Framework基础上开发,那么可以直接选择使用.Net Framework提供的Socket类, ...

  5. jsp struts标签迭代各种数据

    首先创建一个User对象 User user=new User(); user.setUserName("张三"); user.setAge(30); User user1=new ...

  6. 文字处理TX Text Control X10独家揭秘(二):图像占位符合并

    在前面一篇文章<TX Text Control X10独家揭秘(一):数据源自动处理>中已经对即将发布的TX Text Control X10的数据源自动处理做了一些了解,接下来述说它的图 ...

  7. Windows cmd 颜色,字体,color font set up

    windows的cmds默认的字体很丑,丑的不认直视,『如花』一般. 但是总有用到的时候 这是我有优化的一种结果,怎么来弄呢 要字体颜色漂亮,先要在注册表的Console中注册你要使用的字体,这个至关 ...

  8. linux mmap 内存映射【转】

    转自:http://blog.csdn.net/xyyangkun/article/details/7830313 [-] mmap vs readwritelseek mmap vs malloc ...

  9. java多线程中的生产者与消费者之等待唤醒机制@Version1.0

    一.生产者消费者模式的学生类成员变量生产与消费demo,第一版1.等待唤醒:    Object类中提供了三个方法:    wait():等待    notify():唤醒单个线程    notify ...

  10. svn搭建以及可能遇到的问题解决方案

    Svn服务器的安装和配置 1.安装svn服务器端软件从镜像服务器或者YUM源下载安装SVN服务器软件:yum install subversion mkdir /usr/local/svn //创建S ...