zoukankan      html  css  js  c++  java
  • SQLiteHelper Angkor:

    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Data.SQLite;
    using System.Data;
    using System.Data.Common;
    
    namespace Com.Luminji.DataService.SQLHelpers
    {
        public class SQLiteHelper
        {
            /// <summary>
            /// ConnectionString样例:Data Source=Test.db3;Pooling=true;FailIfMissing=false
            /// </summary>
            public static string ConnectionString { get; set; }
    
            private static void PrepareCommand(SQLiteCommand cmd, SQLiteConnection conn, string cmdText, params object[] p)
            {
                if (conn.State != ConnectionState.Open)
                    conn.Open();
                cmd.Parameters.Clear();
                cmd.Connection = conn;
                cmd.CommandText = cmdText;
                cmd.CommandType = CommandType.Text;
                cmd.CommandTimeout = 30;
                if (p != null)
                {
                    foreach (object parm in p)
                        cmd.Parameters.AddWithValue(string.Empty, parm);
                }
            }
    
            public static DataSet ExecuteQuery(string cmdText, params object[] p)
            {
                using (SQLiteConnection conn = new SQLiteConnection(ConnectionString))
                {
                    using (SQLiteCommand command = new SQLiteCommand())
                    {
                        DataSet ds = new DataSet();
                        PrepareCommand(command, conn, cmdText, p);
                        SQLiteDataAdapter da = new SQLiteDataAdapter(command);
                        da.Fill(ds);
                        return ds;
                    }
                }
            }
    
            public static int ExecuteNonQuery(string cmdText, params object[] p)
            {
                using (SQLiteConnection conn = new SQLiteConnection(ConnectionString))
                {
                    using (SQLiteCommand command = new SQLiteCommand())
                    {
                        PrepareCommand(command, conn, cmdText, p);
                        return command.ExecuteNonQuery();
                    }
                }
            }
    
            public static SQLiteDataReader ExecuteReader(string cmdText, params object[] p)
            {
                using (SQLiteConnection conn = new SQLiteConnection(ConnectionString))
                {
                    using (SQLiteCommand command = new SQLiteCommand())
                    {
                        PrepareCommand(command, conn, cmdText, p);
                        return command.ExecuteReader(CommandBehavior.CloseConnection);
                    }
                }
            }
    
            public static object ExecuteScalar(string cmdText, params object[] p)
            {
                using (SQLiteConnection conn = new SQLiteConnection(ConnectionString))
                {
                    using (SQLiteCommand command = new SQLiteCommand())
                    {
                        PrepareCommand(command, conn, cmdText, p);
                        return command.ExecuteScalar();
                    }
                }
            }
    
        }
    }
  • 相关阅读:
    视觉三维重建中不同三角网格视角的选择
    最小二乘求解常数k使得kx=y(x,y为列向量)
    STL常用
    2D-2D:对极几何 基础矩阵F 本质矩阵E 单应矩阵H
    Ubuntu常用软件
    ubuntu linux 安装分区
    单向链表
    1.ssm web项目中的遇到的坑--自定义JQuery插件(slide menu)
    模板引擎freemarker的使用(二)
    模板引擎freemarker的使用(一)
  • 原文地址:https://www.cnblogs.com/wujiakun/p/2230398.html
Copyright © 2011-2022 走看看