首页 > 代码库 > 操作SQLite的dbhelper

操作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