Problema con procedimiento almacenado

13/06/2007 - 17:54 por Jose Antonio | Informe spam
Hola amigos,

abajo les pongo el codigo del procedimiento almacenado y el codigo .net
para manejarlo.

La cuestión es que el procedimiento solo me devuelve la ultima fila
insertada en la tabla, pero debería devolverlos todos. Lo he revisado
todo y no sé si el fallo viene del sql o de código.

El procedimiento usa un cursor, es sqlserver 20000 y recibe 2 parametros
para devolver los registros paginados.

Gracias :)

CREATE PROCEDURE LISTADO_VOLUNTARIOS
@PageSize int,
@PageNumber int
AS
DECLARE cContact CURSOR DYNAMIC READ_ONLY FOR
SELECT ID, IDENTIFICACION, NOMBRE, APELLIDOS
FROM VOLUNTARIOS
ORDER BY APELLIDOS ASC, NOMBRE ASC

OPEN cContact
DECLARE @n int
DECLARE @FirstRecord int
SET @FirstRecord = @PageSize * @PageNumber + 1
FETCH RELATIVE @FirstRecord FROM cContact
SET @n = 1
WHILE @n < @PageSize AND @@FETCH_STATUS = 0
BEGIN
FETCH cContact
SET @n = @n + 1
END
CLOSE cContact
DEALLOCATE cContact
GO


El código:


cnx = New
SqlConnection(ConfigurationSettings.GetConfig("appSettings")("cad"))
cnx.Open()


cmd = New SqlCommand("LISTADO_VOLUNTARIOS", cnx)
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.Add("@PageSize", SqlDbType.Int)
cmd.Parameters("@PageSize").Value ConfigurationSettings.GetConfig("appSettings")("AdmRegXPag")

cmd.Parameters.Add("@PageNumber", SqlDbType.Int)
cmd.Parameters("@PageNumber").Value = page

dr = cmd.ExecuteReader

while dr.read()
response.write("id")
End While
...
 

Leer las respuestas

#1 Isaias
13/06/2007 - 18:38 | Informe spam
Jose

Si tu objetivo es PAGINAR, lee estos links

http://weblogs.sqlteam.com/jeffs/ar.../1085.aspx
http://databases.aspfaq.com/databas...rdset.html
http://www.sqlteam.com/article/serv...erver-2005

Saludos
IIslas


"Jose Antonio" wrote:

Hola amigos,

abajo les pongo el codigo del procedimiento almacenado y el codigo .net
para manejarlo.

La cuestión es que el procedimiento solo me devuelve la ultima fila
insertada en la tabla, pero debería devolverlos todos. Lo he revisado
todo y no sé si el fallo viene del sql o de código.

El procedimiento usa un cursor, es sqlserver 20000 y recibe 2 parametros
para devolver los registros paginados.

Gracias :)

CREATE PROCEDURE LISTADO_VOLUNTARIOS
@PageSize int,
@PageNumber int
AS
DECLARE cContact CURSOR DYNAMIC READ_ONLY FOR
SELECT ID, IDENTIFICACION, NOMBRE, APELLIDOS
FROM VOLUNTARIOS
ORDER BY APELLIDOS ASC, NOMBRE ASC

OPEN cContact
DECLARE @n int
DECLARE @FirstRecord int
SET @FirstRecord = @PageSize * @PageNumber + 1
FETCH RELATIVE @FirstRecord FROM cContact
SET @n = 1
WHILE @n < @PageSize AND @@FETCH_STATUS = 0
BEGIN
FETCH cContact
SET @n = @n + 1
END
CLOSE cContact
DEALLOCATE cContact
GO


El código:


cnx = New
SqlConnection(ConfigurationSettings.GetConfig("appSettings")("cad"))
cnx.Open()


cmd = New SqlCommand("LISTADO_VOLUNTARIOS", cnx)
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.Add("@PageSize", SqlDbType.Int)
cmd.Parameters("@PageSize").Value > ConfigurationSettings.GetConfig("appSettings")("AdmRegXPag")

cmd.Parameters.Add("@PageNumber", SqlDbType.Int)
cmd.Parameters("@PageNumber").Value = page

dr = cmd.ExecuteReader

while dr.read()
response.write("id")
End While


Preguntas similares