SQLiteを操作するdbhelper

3432 ワード

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();

            }

        }

    }