• 大小: 63.41MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-07-18
  • 语言: C#
  • 标签: sqlite  sqlitehelper  C#  

资源简介

一些小型的应用程序需要使用到数据库,sqlite可以说是最好的选择。这里个人整理了一般简单通用的操作类SQLiteHelper

资源截图

代码片段和文件信息

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

namespace ItcastCater.DAL
{
    class SqliteHelper
    {
        //从配置文件中获取数据库连接字符串
        private static readonly string strSqliteConn = ConfigurationManager.ConnectionStrings[“SQLiteConn“].ConnectionString;
        /// 
        /// 由用户指定sql语句可以不传SQLiteParameter的参数但是不能传null
        /// 

        /// 
        /// 
        /// 
        public static int ExecuteNonQuery(string strCmd params SQLiteParameter[] ps)
        {
            using (SQLiteConnection SqliteConn = new SQLiteConnection(strSqliteConn))
            {
                using (SQLiteCommand SqliteCmd = new SQLiteCommand(strCmd SqliteConn))
                {
                    SqliteCmd.Parameters.AddRange(ps);
                    SqliteConn.Open();
                    return SqliteCmd.ExecuteNonQuery();
                }
            }
        }

        public static object ExecuteScalar(string strCmd params SQLiteParameter[] ps)
        {
            using (SQLiteConnection SqliteConn = new SQLiteConnection(strSqliteConn))
            {
                using (SQLiteCommand SqliteCmd = new SQLiteCommand(strCmd SqliteConn))
                {
                    SqliteCmd.Parameters.AddRange(ps);
                    SqliteConn.Open();
                    return SqliteCmd.ExecuteScalar();
                }
            }
        }

        public static SQLiteDataReader ExecuteReader(string strCmd params SQLiteParameter[] ps)
        {
            SQLiteConnection SqliteConn = null;
            try
            {
                SqliteConn = new SQLiteConnection(strSqliteConn);
                using (SQLiteCommand SqliteCmd = new SQLiteCommand(strCmd SqliteConn))
                {
                    SqliteCmd.Parameters.AddRange(ps);
                    SqliteConn.Open();
                    return SqliteCmd.ExecuteReader(CommandBehavior.CloseConnection);
                }
            }
            catch (Exception e)
            {
                if (SqliteConn != null)
                {
                    SqliteConn.Dispose();

                }

                throw e;
            }
            
        }

        public static DataTable ExecuteTable(string strCmd params SQLiteParameter[] ps)
        {
            using (SQLiteDataAdapter SqliteAdapter = new SQLiteDataAdapter(strCmdstrSqliteConn))
            {
                SqliteAdapter.SelectCommand.Parameters.AddRange(ps);
                DataTable table = new DataTable();
                SqliteAdapter.Fill(table);
                return table;
            }
        }
    }

public enum ExecuteMode{
ExecuteNonQuery
ExecuteScalar
ExecuteReader

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2017-09-18 11:22  sqlite相关文件\
     目录           0  2017-09-18 11:21  sqlite相关文件\SQLite.shell.dll4cs.manage\
     文件     8610642  2017-09-18 11:14  sqlite相关文件\SQLite.shell.dll4cs.manage\sqlite-netFx35-setup-bundle-x64-2008-1.0.105.2.exe
     文件     7805153  2017-09-18 11:12  sqlite相关文件\SQLite.shell.dll4cs.manage\sqlite-netFx35-setup-bundle-x86-2008-1.0.105.2.exe
     文件    13158087  2014-04-03 17:49  sqlite相关文件\SQLite.shell.dll4cs.manage\sqlite-netFx40-setup-bundle-x86-2010-1.0.92.0.exe
     文件      536064  2014-03-27 02:13  sqlite相关文件\SQLite.shell.dll4cs.manage\sqlite3.exe
     文件     5527942  2014-04-03 17:50  sqlite相关文件\SQLite.shell.dll4cs.manage\sqlitestudio-2.1.4.exe
     文件        3081  2014-04-27 15:03  sqlite相关文件\SQLiteHelper.cs
     文件      847872  2014-04-03 17:48  sqlite相关文件\System.Data.SQLite.dll
     文件    31850803  2014-04-03 17:50  sqlite相关文件\《SQLite权威指南(第二版)》.(Grant Allen等).[PDF]&ckook.pdf

评论

共有 条评论