public static Dictionary <K, V> BindSourceData <K, V>(this string keyIDString, string connectionKeyOrConnectionString, string tableName, string keyField, string nameFiled) { Dictionary <K, V> dictionary = new Dictionary <K, V>(); if (!string.IsNullOrWhiteSpace(keyIDString)) { if (typeof(K) == typeof(string)) { keyIDString = keyIDString.ConvertStringID(); } string commandText = string.Format("SELECT DISTINCT {0},{1} FROM {2} where {0} in ({3})", new object[] { keyField, nameFiled, tableName, keyIDString }); foreach (DataRow row in MySqlHelper.ExecuteDataTable(connectionKeyOrConnectionString, commandText, new MySqlParameter[0]).Rows) { dictionary.Add((K)row[keyField], (V)row[nameFiled]); } } return(dictionary); }
public static Dictionary <K, V> BindDataKeyValue <K, V>(string connectionKeyOrConnectionString, string tableName, string condition, string sort, string keyField, string nameFiled) { Dictionary <K, V> dictionary = new Dictionary <K, V>(); string commandText = string.Format("SELECT DISTINCT {0},{1} FROM {2}", keyField, nameFiled, tableName); if (!string.IsNullOrWhiteSpace(condition)) { commandText = commandText + " where " + condition; } if (!string.IsNullOrWhiteSpace(sort)) { commandText = commandText + " order by " + sort; } foreach (DataRow row in MySqlHelper.ExecuteDataTable(connectionKeyOrConnectionString, commandText, new MySqlParameter[0]).Rows) { dictionary.Add((K)row[keyField], (V)row[nameFiled]); } return(dictionary); }