SqliteHelper
来源:互联网 发布:如何进入数据库平台 编辑:程序博客网 时间:2024/05/10 14:00
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Data;using System.Data.SQLite;using System.Configuration;namespace DAL{ public class SqliteHelper { //获取连接字符串 private static readonly string str = ConfigurationManager.ConnectionStrings["conStr"].ConnectionString; /// <summary> /// 做增删改的功能 /// </summary> /// <param name="sql">SQL语句</param> /// <param name="ps">SQL语句中的参数</param> /// <returns>受影响的行数</returns> public static int ExecuteNonQuery(string sql, params SQLiteParameter[] ps) { //连接数据库 using (SQLiteConnection con=new SQLiteConnection(str)) { using (SQLiteCommand cmd =new SQLiteCommand(sql,con)) { con.Open();//打开数据库 if (ps!=null) { cmd.Parameters.AddRange(ps);//参数,加集合(ps) } return cmd.ExecuteNonQuery(); } } } /// <summary> /// 查询首行首列 /// </summary> /// <param name="sql">SQL语句</param> /// <param name="ps">SQL语句的参数</param> /// <returns>返回首行首列object</returns> public static object ExecuteScalar(string sql, params SQLiteParameter[] ps) { using (SQLiteConnection con=new SQLiteConnection(str)) { using (SQLiteCommand cmd=new SQLiteCommand(sql,con)) { con.Open(); if (ps!=null) { cmd.Parameters.AddRange(ps); } return cmd.ExecuteScalar(); } } } /// <summary> /// 查询多行 /// </summary> /// <param name="sql">SQL语句</param> /// <param name="ps">SQL语句的参数</param> /// <returns>返回多行SQLiteDataReader</returns> public static SQLiteDataReader ExecuteReader(string sql, params SQLiteParameter[] ps) { SQLiteConnection con = new SQLiteConnection(str); using (SQLiteCommand cmd=new SQLiteCommand(sql,con)) { if (ps!=null) { cmd.Parameters.AddRange(ps); } try { con.Open(); return cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection); } catch (Exception ex) { con.Close(); con.Dispose(); throw ex; } } } /// <summary> /// 查询数据表 /// </summary> /// <param name="sql">SQL语句</param> /// <param name="ps">SQL语句中的参数</param> /// <returns>返回表DataTable</returns> public static DataTable ExecuteTable(string sql, params SQLiteParameter[] ps) { DataTable dt = new DataTable(); using (SQLiteDataAdapter sda=new SQLiteDataAdapter(sql,str)) { if (ps!=null) { sda.SelectCommand.Parameters.AddRange(ps); } sda.Fill(dt); return dt; } } }}
0 0
- Sqlitehelper
- SQLiteHelper
- SQLiteHelper
- SQLiteHelper
- SQLiteHelper
- SqliteHelper
- SqliteHelper
- SQLiteHelper
- SqliteHelper类
- SqliteHelper抄袭
- SQLiteHelper的C#实现
- SQLiteHelper-SQLite帮助类
- android SqliteHelper的使用
- 【C#】sqlitehelper类
- 积累——SQLiteHelper
- 再来一个SqliteHelper,项目中用的
- SQLiteHelper类,操作SQLite数据库
- 使用SQLiteHelper创建数据库并插入数据
- 浅谈MVC思想
- Android性能优化工具
- 容器技术及其应用白皮书(上)-- 容器技术
- Table
- 342. Power of Four
- SqliteHelper
- openGL三维网格坐标,旋转,缩放,灯光设置,纹理读取,模型读取(MFC单文档)
- Sublime Text 主题设置
- 锁机病毒续
- 模拟简易图片轮播以及效果图
- eclipse启动tomcat 卡住preparing launch delegate
- android 获取系统默认路径
- 关于Js OOP编程 创建对象的一些理解。
- android 第三方引用框架