C# SQLite通用读写操作方法

2017-06-26 19:22:46来源:CSDN作者:qq_36011182人点击

        /// <summary>        /// 执行SQL语句,返回影响的记录数        /// </summary>        /// <param name="SQLString">SQL语句</param>        /// <returns>影响的记录数</returns>        public static int ExecuteSql(string SQLString)        {            lock (_lock)            {                using (SQLiteConnection sqliteConn = new SQLiteConnection(sqlConnectionString))                {                    sqliteConn.Open();                    using (SQLiteCommand cmd = sqliteConn.CreateCommand())                    {                        try                        {                            cmd.CommandText = SQLString;                            int rows = cmd.ExecuteNonQuery();                            return rows;                        }                        catch (SQLiteException ex)                        {                            throw ex;                        }                        finally                        {                            sqliteConn.Close();                        }                    }                }            }        }        /// <summary>        /// 执行查询语句,返回DataTable,DataSet的第一张表        /// </summary>        /// <param name="SQLString">查询语句</param>        /// <returns>DataTable</returns>        public static DataTable Query(string SQLString)        {            using (SQLiteConnection sqliteConn = new SQLiteConnection(sqlConnectionString))            {                try                {                    sqliteConn.Open();                    DataSet ds = new DataSet();                    SQLiteDataAdapter sqliteDa = new SQLiteDataAdapter(SQLString, sqliteConn);                    sqliteDa.Fill(ds);                    return ds.Tables[0];                }                catch (SQLiteException ex)                {                    throw ex;                }                finally                {                    sqliteConn.Close();                }            }        }


最新文章

123

最新摄影

闪念基因

微信扫一扫

第七城市微信公众平台