/// <summary> /// 查询该表信息 /// </summary> /// <param name="where">指定的查询条件</param> /// <param name="prams">对字符串进行映射</param> /// <param name="fields">要查询的字段</param> /// <returns><see cref="DataTable"/>对象</returns> public DataTable Get(string where, object prams, params string[] fields) { if (fields == null || fields.Length == 0) { throw new ArgumentException("在准备修改表的时候发生异常,键值对集合为空!", "错误提示:"); } StringBuilder key = new StringBuilder(); foreach (string field in fields) { key.AppendFormat("[{0}],", field); } string commandText = string.Format("SELECT {0} FROM {1} {2}", key.ToString(0, key.Length - 1), this.TableName, DbHelperExensions.WhereStr(where)); DataSet dataSet = Database.ExecuteDataset(commandText, prams); if (!dataSet.IsEmpty()) { return(dataSet.Tables[0]); } return(null); }
/// <summary> /// 修改数据 /// </summary> /// <param name="keyValues">修改的键值对集合</param> /// <param name="where">指定的修改的条件</param> public int Update(Dictionary <string, object> keyValues, string where) { if (keyValues == null || keyValues.Count == 0) { throw new ArgumentException("在准备修改表的时候发生异常,键值对集合为空!", "错误提示:"); } //StringBuilder stringBuilder = new StringBuilder(); //List<DbParameter> parms = new List<DbParameter>(); //foreach (KeyValuePair<string, object> keyValue in keyValues) //{ // stringBuilder.AppendFormat("[{0}] = @{0},", keyValue.Key); // parms.Add(Database.MakeInParam(keyValue.Key, keyValue.Value)); //} //stringBuilder.Remove(stringBuilder.Length - 1, 1); List <DbParameter> parms = Database.GetUpdateParams(keyValues, out string strsql); string commandText = string.Format("UPDATE {0} SET {1} {2}", this.TableName, strsql, DbHelperExensions.WhereStr(where)); return(Database.ExecuteNonQuery(CommandType.Text, commandText, parms.ToArray())); }
/// <summary> /// 查询该表信息 /// </summary> /// <param name="where">指定的查询条件</param> /// <param name="prams">对字符串进行映射</param> /// <returns><see cref="DataTable"/>对象</returns> public DataTable Get(string where, object prams) { string commandText = string.Format("SELECT * FROM {0} {1}", this.TableName, DbHelperExensions.WhereStr(where)); DataSet dataSet = Database.ExecuteDataset(commandText, prams); if (!dataSet.IsEmpty()) { return(dataSet.Tables[0]); } return(null); }
/// <summary> /// 删除该表数据 /// </summary> /// <param name="where">指定的删除条件</param> /// <param name="prams">对字符串进行映射</param> /// <returns>受影响行数</returns> public int Delete(string where, object prams) { string commandText = string.Format("DELETE FROM {0} {1}", this.TableName, DbHelperExensions.WhereStr(where)); return(Database.ExecuteNonQuery(commandText, prams)); }