public static void AddUserConfig(UserConfig userConfig) { using (var sqlConn = new SQLiteConnection(ConnectionString)) { try { sqlConn.Open(); var cmd = sqlConn.CreateCommand(); cmd.CommandText = string.Format("insert into TB_Config([Name],[Config]) values('UserConfig',@Config);"); cmd.Parameters.Add(new SQLiteParameter("@Config", ObjectEx.ToBinary(userConfig))); cmd.ExecuteNonQuery(); } catch (Exception) { sqlConn.Close(); } } }
public static void ModifyUserConfig(UserConfig userConfig) { using (var sqlConn = new SQLiteConnection(ConnectionString)) { try { sqlConn.Open(); var cmd = sqlConn.CreateCommand(); cmd.CommandText = string.Format("update TB_Config set Config=@Config where [Name]='UserConfig'"); cmd.Parameters.Add(new SQLiteParameter("@Config", ObjectEx.ToBinary(userConfig))); cmd.ExecuteNonQuery(); } catch (Exception) { sqlConn.Close(); } } }
public static UserConfig GetUserConfig() { using (var sqlConn = new SQLiteConnection(ConnectionString)) { try { sqlConn.Open(); var cmd = sqlConn.CreateCommand(); cmd.CommandText = "select Config from TB_Config where name='UserConfig'"; var data = cmd.ExecuteScalar(); if (data == null) { return(null); } return(ObjectEx.FromBinary <UserConfig>((byte[])data)); } catch (Exception) { sqlConn.Close(); } } return(null); }