Пример #1
0
        public T QuerySql <T>(string sql, string connectionString) where T : class
        {
            var dbconnection = new SQLiteConnection(connectionString);

            try
            {
                var dbcommand = new SQLiteCommand();
                dbcommand.Connection = dbconnection;
                var dba = new SQLiteDataAdapter(dbcommand);
                if (dbconnection.State == ConnectionState.Closed)
                {
                    dbconnection.Open();
                }
                dbcommand.CommandText = $"{sql};";
                var dt = new DataTable();
                dba.Fill(dt);
                var json = JsonSerialzer.SerializeObject(dt.ToDictionary("yyyy/MM/dd HH:mm:ss"));
                dba.Dispose();
                return(JsonSerialzer.DeserializeObject <T>(json));
            }
            catch (Exception ex)
            {
                LogManager.WriteLog(ex.Message);
                throw ex;
            }
            finally
            {
                dbconnection.Close();
            }
        }
Пример #2
0
 static SqliteDBHelper()
 {
     JsonSerialzer = new JsonSerialzer();
     LogManager    = new LogManager();
 }