public void Add(TKey key, TValue value) { var stm = string.Format("INSERT INTO {0} ({1}, {2}) VALUES ({3}, {4})", _tableName, DBFields <TKey> .Fields, DBFields <TValue> .Fields, DBFields <TKey> .Values(key), DBFields <TValue> .Values(value)); if (ExecuteNonQuery(stm)) { try { _dict.Add(key, value); } catch (ArgumentException) // dup keys, np { } } }
public TValue this[TKey key] { get { return(_dict[key]); } set { if (!_dict.ContainsKey(key)) { Add(key, value); } else { var stm = string.Format("UPDATE {0} SET {1} WHERE {2}", _tableName, DBFields <TValue> .FieldsAndValues(value, " , "), DBFields <TKey> .FieldsAndValues(key, " AND ")); if (ExecuteNonQuery(stm)) { _dict[key] = value; } } } }
public bool Remove(TKey key) { var stm = string.Format("DELETE FROM {0} WHERE {1}", _tableName, DBFields <TKey> .FieldsAndValues(key, " AND ")); return(ExecuteNonQuery(stm) && _dict.Remove(key)); }