/// <summary> /// 执行Transaction,完成后关闭连接 /// </summary> /// <param name="sqls">sql数组</param> /// <returns>总影响条数,返回0为事务执行失败</returns> public static int ExecuteTransaction(string[] sqls) { int i = 0; DBHelperBase _DBHelper = null; try { _DBHelper = CreateHelper(); _DBHelper.BeginTransaction(); foreach (string sql in sqls) { _DBHelper.ExecuteNoQuery(sql); i++; } _DBHelper.CommitTransaction(); return(i); } catch (Exception ex) { _DBHelper.RollbackTransaction(); throw ex; } finally { if (_DBHelper != null) { _DBHelper.Close(); } } }
public static DataTable ExecuteQuery(string sql, string tableName) { DBHelperBase _DBHelper = null; try { _DBHelper = CreateHelper(); return(_DBHelper.ExecuteQuery(sql, tableName)); } catch (Exception ex) { throw ex; } finally { if (_DBHelper != null) { _DBHelper.Close(); } } }
/// <summary> /// 非查询操作 /// </summary> /// <param name="sql">sql字符串</param> /// <param name="parameters">参数集合</param> /// <returns></returns> public static object ExecuteScalar(string sql) { DBHelperBase _DBHelper = null; try { _DBHelper = CreateHelper(); return(_DBHelper.ExecuteScalar(sql)); } catch (Exception ex) { throw ex; } finally { if (_DBHelper != null) { _DBHelper.Close(); } } }
/// <summary> /// 非查询操作 /// </summary> /// <param name="sql">sql字符串</param> /// <param name="parameters">参数集合</param> /// <returns></returns> public static int ExecuteNoQuery(string sql, DBHelperParmCollection parameters) { DBHelperBase _DBHelper = null; try { _DBHelper = CreateHelper(); return(_DBHelper.ExecuteNoQuery(sql, parameters)); } catch (Exception ex) { throw ex; } finally { if (_DBHelper != null) { _DBHelper.Close(); } } }
/// <summary> /// 非查询操作 /// </summary> /// <param name="sql"></param> /// <returns></returns> public static int ExecuteNoQuery(StringBuilder sbsql) { DBHelperBase _DBHelper = null; try { _DBHelper = CreateHelper(); return(_DBHelper.ExecuteNoQuery(sbsql.ToString())); } catch (Exception ex) { throw ex; } finally { if (_DBHelper != null) { _DBHelper.Close(); } } }
/// <summary> /// 查询操作 返回DataSet /// </summary> /// <param name="sql"></param> /// <returns></returns> public static DataSet GetDataSet(string sql) { DBHelperBase _DBHelper = null; try { _DBHelper = CreateHelper(); return(_DBHelper.GetDataSet(sql)); } catch (Exception ex) { throw ex; } finally { if (_DBHelper != null) { _DBHelper.Close(); } } }
private static DBHelperBase CreateHelper() { DBHelperBase _DBHelper = null; try { if (_ConnStr.Length > 0) { _DBHelper = DBHelperFactory.CreateHelper(_DBType, _ConnStr, _DBEncoding); } else { _DBHelper = DBHelperFactory.CreateDBHelper(); } _DBHelper.Open(); return(_DBHelper); } catch (Exception ex) { throw new DBOpenException(ex); } }