码迷,mamicode.com
首页 > 数据库 > 详细

操作SQLite的dbhelper

时间:2014-08-31 18:29:21      阅读:318      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   io   ar   div   cti   log   sp   

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

标签:style   blog   color   io   ar   div   cti   log   sp   

原文地址:http://www.cnblogs.com/jaday/p/3947916.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!