/// <summary> /// 返回查询结果中第一行第一列 /// </summary> /// <param name="commandText"></param> /// <param name="parameters"></param> /// <param name="cmdType"></param> /// <param name="type"></param> /// <param name="adapter"></param> /// <param name="dbString">分库名</param> /// <returns></returns> public static object ExcuteScalar3(string commandText, IList <IDbDataParameter> parameters = null, CommandType cmdType = CommandType.Text, DbConntionType type = DbConntionType.OnlyRead, FluDataAdapter adapter = null, string dbString = null) { if (adapter == null) { using (FluDataAdapter da = GetAdapter3(commandText, parameters, cmdType, type, dbString)) { da.OpenConnection(); object obj = da.SelectCommand.ExecuteScalar(); da.CloseConnection(); return(obj); } } adapter.ClearParameter(); adapter.CommandText = commandText; adapter.CommandType = cmdType; if (parameters != null) { foreach (var p in parameters) { adapter.AddParameter(p); } } object result2 = adapter.SelectCommand.ExecuteScalar(); return(result2); }
/// <summary> /// 返回查询结果中第一行第一列 /// </summary> /// <param name="commandText"></param> /// <param name="cmdType"></param> /// <param name="paraName"></param> /// <param name="paraValue"></param> /// <param name="type"></param> /// <param name="adapter"></param> /// <param name="dbString">分库名</param> /// <returns></returns> public static object ExcuteScalar(string commandText, CommandType cmdType = CommandType.Text, string[] paraName = null, object[] paraValue = null, DbConntionType type = DbConntionType.OnlyRead, FluDataAdapter adapter = null, string dbString = null) { if (adapter == null) { using (FluDataAdapter da = GetAdapter(commandText, cmdType, paraName, paraValue, type, dbString)) { da.OpenConnection(); object obj = da.SelectCommand.ExecuteScalar(); da.CloseConnection(); return(obj); } } adapter.ClearParameter(); adapter.CommandText = commandText; adapter.CommandType = cmdType; if (paraName != null && paraValue != null && paraName.Length == paraValue.Length) { for (int i = 0; i < paraName.Length; i++) { adapter.AddParameter(paraName[i], paraValue[i]); } } object result2 = adapter.SelectCommand.ExecuteScalar(); return(result2); }
/// <summary> /// 执行SQL语句 /// </summary> /// <param name="commandText"></param> /// <param name="parameters">参数化列表</param> /// <param name="cmdType"></param> /// <param name="adapter"></param> /// <param name="dbString">分库名</param> /// <returns></returns> public static int ExcuteNonQuery3(string commandText, IList <IDbDataParameter> parameters = null, CommandType cmdType = CommandType.Text, FluDataAdapter adapter = null, string dbString = null) { if (adapter == null) { using (adapter = GetAdapter3(commandText, parameters, cmdType, DbConntionType.WriteRead, dbString)) { adapter.OpenConnection(); int result = adapter.SelectCommand.ExecuteNonQuery(); adapter.CloseConnection(); return(result); } } adapter.ClearParameter(); adapter.CommandText = commandText; adapter.CommandType = cmdType; if (parameters != null) { foreach (var p in parameters) { adapter.AddParameter(p); } } int result2 = adapter.SelectCommand.ExecuteNonQuery(); return(result2); }
/// <summary> /// 执行SQL语句 /// </summary> /// <param name="commandText"></param> /// <param name="cmdType"></param> /// <param name="paraName">参数名数组</param> /// <param name="paraValue">参数值数组</param> /// <param name="adapter">是否外部传递,如使用事务</param> /// <param name="dbString">分库名</param> /// <returns></returns> public static int ExcuteNonQuery(string commandText, CommandType cmdType = CommandType.Text, string[] paraName = null, object[] paraValue = null, FluDataAdapter adapter = null, string dbString = null) { if (adapter == null) { using (adapter = GetAdapter(commandText, cmdType, paraName, paraValue, DbConntionType.WriteRead, dbString)) { adapter.OpenConnection(); int result = adapter.SelectCommand.ExecuteNonQuery(); adapter.CloseConnection(); return(result); } } adapter.ClearParameter(); adapter.CommandText = commandText; adapter.CommandType = cmdType; if (paraName != null && paraValue != null && paraName.Length == paraValue.Length) { for (int i = 0; i < paraName.Length; i++) { adapter.AddParameter(paraName[i], paraValue[i]); } } int result2 = adapter.SelectCommand.ExecuteNonQuery(); return(result2); }
/// <summary> /// 获取数据操作适配器,须执行dispose /// </summary> /// <param name="commandText"></param> /// <param name="parameters"></param> /// <param name="cmdType"></param> /// <param name="type"></param> /// <param name="dbString"></param> /// <returns></returns> public static FluDataAdapter GetAdapter3(string commandText = null, IList <IDbDataParameter> parameters = null, CommandType cmdType = CommandType.Text, DbConntionType type = DbConntionType.WriteRead, string dbString = null) { FluDataAdapter da = new FluDataAdapter(type, dbString); da.CommandText = commandText; da.CommandType = cmdType; if (parameters != null) { foreach (var item in parameters) { da.AddParameter(item); } } if (da.ShowSql) { SetSqlShow(commandText, dbParameters: parameters); } return(da); }
/// <summary> /// 获取数据操作适配器 /// </summary> /// <param name="commandText"></param> /// <param name="parameters"></param> /// <param name="cmdType"></param> /// <param name="type"></param> /// <param name="dbString"></param> /// <returns></returns> public static FluDataAdapter GetAdapter2(string commandText = null, IDictionary <string, object> parameters = null, CommandType cmdType = CommandType.Text, DbConntionType type = DbConntionType.WriteRead, string dbString = null) { FluDataAdapter da = new FluDataAdapter(type, dbString); da.CommandText = commandText; da.CommandType = cmdType; if (parameters != null) { foreach (var item in parameters) { da.AddParameter(item.Key, item.Value); } } if (da.ShowSql) { SetSqlShow(commandText, parameters: parameters); } return(da); }
/// <summary> /// 获取数据操作适配器 /// </summary> /// <param name="commandText"></param> /// <param name="cmdType"></param> /// <param name="paraName"></param> /// <param name="paraValue"></param> /// <param name="type"></param> /// <param name="dbString"></param> /// <returns></returns> public static FluDataAdapter GetAdapter(string commandText = null, CommandType cmdType = CommandType.Text, string[] paraName = null, object[] paraValue = null, DbConntionType type = DbConntionType.WriteRead, string dbString = null) { FluDataAdapter da = new FluDataAdapter(type, dbString); da.CommandText = commandText; da.CommandType = cmdType; da.ClearParameter(); if (paraName != null && paraValue != null && paraName.Length == paraValue.Length) { for (int i = 0; i < paraName.Length; i++) { da.AddParameter(paraName[i], paraValue[i]); } } if (da.ShowSql) { SetSqlShow(commandText, paraName, paraValue); } return(da); }