return SQLHelper.ExecuteReaderAndCount(SQLHelper.ConnectioinString, CommandType.StoredProcedure, "call GetMediaInfoNewNoApprove(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,@count)", out count,getMediaByRd, par);
/// <summary> /// 带总数量的查询 /// </summary> /// <param name="connectionString"></param> /// <param name="cmdType"></param> /// <param name="cmdText"></param> /// <param name="commandParameters"></param> /// <returns></returns> public static DataTable ExecuteReaderAndCount(string connectionString, CommandType cmdType, string cmdText, out int count,gettablebyRd gettable, params OdbcParameter[] commandParameters) { OdbcCommand cmd = new OdbcCommand(); OdbcConnection conn = new OdbcConnection(connectionString);
// we use a try/catch here because if the method throws an exception we want to // close the connection throw code, because no datareader will exist, hence the // commandBehaviour.CloseConnection will not work try { count = 0; PrepareCommand(cmd, conn, null, cmdType, cmdText, commandParameters);
OdbcParameter _p = new OdbcParameter("@count",OdbcType.Int); _p.Direction = ParameterDirection.Output; cmd.Parameters.Add(_p); OdbcDataReader rdr = cmd.ExecuteReader(); DataTable dt= gettable(rdr); cmd.CommandText = "select @count"; count = int.Parse(cmd.ExecuteScalar().ToString()); cmd.Parameters.Clear(); return dt; } catch { count = 0; conn.Close(); throw; }
}