/// <summary> /// 执行查询语句,返回DataSet /// </summary> /// <param name="strSql">查询语句</param> /// <returns>DataSet</returns> public static DataSet Query(string strSql, params CommonParameter[] cmdParms) { using (DbConnection connection = ConnectionMgr.GetConnection()) { DataSet ds = new DataSet(); try { connection.Open(); DbCommand cmd = BuildSQLCommand(connection, strSql, cmdParms); DbDataAdapter myReader = ConnectionMgr.CreateDbDataAdapter(cmd); myReader.Fill(ds, "ds"); } catch (DbException ex) { throw new Exception(ex.Message); } finally { connection.Close(); } return(ds); } }
/// <summary> /// 执行存储过程,返回DataSet /// </summary> /// <param name="storedProcName">存储过程名</param> /// <param name="parameters">存储过程参数</param> /// <param name="tableName">DataSet结果中的表名</param> /// <returns>DataSet</returns> public static DataSet RunProcedure(string storedProcName, CommonParameter[] parameters) { using (DbConnection connection = ConnectionMgr.GetConnection()) { DataSet ds = new DataSet(); try { connection.Open(); DbCommand cmd = BuildProcedureCommand(connection, storedProcName, parameters); DbDataAdapter myReader = ConnectionMgr.CreateDbDataAdapter(cmd); myReader.Fill(ds, "ds"); } catch (DbException ex) { throw new Exception(ex.Message); } finally { connection.Close(); } return(ds); } }
/// <summary> /// 带超时设置的数据查询 /// </summary> /// <param name="SQLString"></param> /// <param name="Times"></param> /// <returns></returns> public static DataSet Query(string SQLString, int Times) { using (DbConnection connection = ConnectionMgr.GetConnection()) { DataSet ds = new DataSet(); try { connection.Open(); DbCommand cmd = BuildSQLCommand(connection, SQLString, null); cmd.CommandTimeout = Times; DbDataAdapter myReader = ConnectionMgr.CreateDbDataAdapter(cmd); myReader.Fill(ds, "ds"); } catch (DbException ex) { throw new Exception(ex.Message); } finally { connection.Close(); } return(ds); } }