System.Data.Sqlite for winform

前端之家收集整理的这篇文章主要介绍了System.Data.Sqlite for winform前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
项目中想要引用System.Data.sqlite,一番查询,需要安装过[ADO.NET 2.0 Provider for sqlite](http://download.csdn.net/detail/mh942408056/9500484) ,通过引用其中System.Data.sqlite可以访问sqlite 数据库,不过目前只支持到framowork4.0以下,4.0以上包括4.0,无法使用。
@H_502_3@sqlite帮助类:
using System.Data;
using System.Data.sqlite;

namespace DTS.Winfrm.res.code
{
    public class sqliteHelper
     {
        private static sqliteConnection GetConnection()
        {
            string connStr = System.Configuration.ConfigurationSettings.AppSettings["sqlite"].ToString();
            sqliteConnection conn = new sqliteConnection(connStr);
            conn.Open();
            return conn;
        }

        public static int Executesql(string sql)
        {
            using (sqliteConnection conn = GetConnection())
            {
                var cmd = new sqliteCommand(sql,conn);
                return cmd.ExecuteNonQuery();
            }
        }

        public static int ExecuteScalar(string sql)
        {
            using (sqliteConnection conn = GetConnection())
            {
                var cmd = new sqliteCommand(sql,conn);
                object o = cmd.ExecuteScalar();
                return int.Parse(o.ToString());
            }
        }
        public static sqliteDataReader ExecuteReader(string sql)
        {
            sqliteConnection conn = GetConnection();
            var cmd = new sqliteCommand(sql,conn);
            sqliteDataReader myReader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
            return myReader;
        }
        public static DataSet ExecDataSet(string sql)
        {
            using (sqliteConnection conn = GetConnection())
            {
                var cmd = new sqliteCommand(sql,conn);
                sqliteDataAdapter da = new sqliteDataAdapter(cmd);
                DataSet ds = new DataSet();
                da.Fill(ds);

                return ds;
            }
        }
    }
}
原文链接:https://www.f2er.com/sqlite/198931.html

猜你在找的Sqlite相关文章