操作SQLite的dbhelper

操作SQLite的dbhelper

public class DbHelper
    {
        string connStr = @"Data Source=" + System.Environment.CurrentDirectory + @"\workhelper.db;Initial Catalog=sqlite;Integrated Security=True;Max Pool Size=10";
        /// <summary>
        /// 执行增删改
        /// </summary>
        /// <param name="sqlStr"></param>
        public bool ExecuteSql(string sqlStr)
        {
            using (DbConnection conn = new SQLiteConnection(connStr))
            {
                conn.Open();
                var comm = conn.CreateCommand();
                comm.CommandText = sqlStr;
                comm.CommandType = CommandType.Text;
                return comm.ExecuteNonQuery() > 0;
            }
        }
        /// <summary>
        /// 执行查询返回DataSet
        /// </summary>
        /// <param name="sqlStr"></param>
        /// <returns></returns>
        public DbDataReader ExecuteString(string sqlStr)
        {
            using (DbConnection conn = new SQLiteConnection(connStr))
            {
                conn.Open();
                var cmd = conn.CreateCommand();
                cmd.CommandText = sqlStr;
                cmd.CommandType = CommandType.Text;
                return cmd.ExecuteReader();
            }
        }
    }

 

操作SQLite的dbhelper

上一篇:MySQL 中如何在触发器里中断记录的插入或更新?


下一篇:MySQL命令行乱码问题的解决