locked
About paging an objectdatasource RRS feed

  • Question

  • User1256512446 posted

    Hi all:

    I have an objectdatasource

        <asp:ObjectDataSource ID="objdspuntosganados" TypeName="comercial.puntos_ganados_datospersonales" SelectCountMethod="seleccionar_cuenta" EnablePaging="true" SelectMethod="seleccionar_todo" StartRowIndexParameterName="comienzo" MaximumRowsParameterName="maximonumeroregistros" SortParameterName="orden" runat="server" >
            <SelectParameters>
                <asp:Parameter Name="condicion" DefaultValue=" "  />
                <asp:CookieParameter name="c10" CookieName="cuenta"/>
                <asp:QueryStringParameter Name="idioma" QueryStringField="idioma" />
            </SelectParameters>
        </asp:ObjectDataSource>
    

    This is the BAL

        Public Class puntos_ganados_datospersonales
    
            Public Function seleccionar_todo(ByVal idioma As Integer, ByVal c10 As Integer, ByVal orden As String, ByVal comienzo As Integer, ByVal maximonumeroregistros As Integer, ByVal condicion As String) As DataSet
                Dim cnconexion As New SqlConnection(ConfigurationManager.ConnectionStrings("Cresolia").ConnectionString)
                Dim sqlc As New SqlCommand("seleccionar_puntos_ganados_datospersonales", cnconexion)
                Dim da As SqlDataAdapter = New SqlDataAdapter(sqlc), ds As DataSet = New DataSet()
                sqlc.CommandType = CommandType.StoredProcedure
                sqlc.Parameters.AddWithValue("@idioma", idioma)
                sqlc.Parameters.AddWithValue("@c10", c10)
                sqlc.Parameters.AddWithValue("@orden", orden)
                sqlc.Parameters.AddWithValue("@comienzo", comienzo)
                sqlc.Parameters.AddWithValue("@maximonumeroregistros", maximonumeroregistros)
                sqlc.Parameters.AddWithValue("@condicion", condicion)
                cnconexion.Open()
                da.Fill(ds)
                cnconexion.Close()
                Return ds
            End Function
    
            Public Function seleccionar_cuenta(ByVal idioma As Integer, ByVal c10 As Integer, ByVal condicion As String) As Integer
                Dim cnconexion As New SqlConnection(ConfigurationManager.ConnectionStrings("Cresolia").ConnectionString)
                Dim sqlc As New SqlCommand("seleccionar_numeroregistros_puntos_ganados_datospersonales", cnconexion)
                Dim intnumeroregistros As Integer
                sqlc.CommandType = CommandType.StoredProcedure
                sqlc.Parameters.AddWithValue("@idioma", idioma)
                sqlc.Parameters.AddWithValue("@c10", c10)
                sqlc.Parameters.AddWithValue("@condicion", condicion)
                cnconexion.Open()
                intnumeroregistros = CInt(sqlc.ExecuteScalar())
                cnconexion.Close()
                Return intnumeroregistros
            End Function
    
        End Class
    

    In the sp I have

    	set @comienzo+=1
    	set @fin=@comienzo+@maximonumeroregistros-1
    ...
    
    	select pg0,p0,case @idioma when 1 then ''destino: valoración de ''+(select obra_espanol from dbo.obras where o0=16) when 2 then ''destiny: ''+(select obra_ingles from dbo.obras where o0=16)+'' valuation'' when 3 then ''destin: évaluation des ''+(select obra_frances from dbo.obras where o0=16) when 4 then ''destino: valoração de ''+(select obra_portugues from dbo.obras where o0=16) end,libro,fecha,null,puntos
    	from dbo.[puntos ganados] inner join dbo.[valoraciones poemas] on vp0=pg3 inner join dbo.poemas on p0=vp1 where pg1=2 and pg2=51 and p2=@c10
    	) tabla0'+ @condicion+') tabla1 where numero between @comienzo and @fin'
    
    

    The gridview has 16 records and gridview.pagesize=25

    However only 10 records are shown. And it doesn't paginate.

    What is wrong? Do I forget something?

    TIA

    Sunday, November 29, 2015 5:36 PM

All replies

  • User1256512446 posted

    Hi again:

    If I put in the sp set @fin=21 then all the records are shown.

    ¿What is wrong?

    TIA

    Sunday, November 29, 2015 5:51 PM
  • User1686483761 posted

    If I put in the sp set @fin=21 then all the records are shown.

    ¿What is wrong?

    I don't think your have any problems. Your Stored Procedure could performance without getting error message. So if you think the result is not correct, you could compare the result in your application and database, and check if the result is the same. I guess that your Stored Procedure have some problems so that you couldn't get the correctly result.

    Monday, November 30, 2015 8:24 AM
  • User1256512446 posted

    Hi again:

    Right. My sp is correct.

    I tested the @maximonumeroregistros in the sp. It is 10.

    However the pagesize is 25.

    Is it not the @maximonumeroregistros equal to pagesize?

    I tested it in management studio. If I put @maximonumeroregistros to 25 it is ok, it shows all the records. If I put 10 it shows only 10

    TIA

    Monday, November 30, 2015 9:44 AM
  • User1256512446 posted

    Hi again:

    I coud put the @maximonumeroregistros in the sp. This value, I think,, is the pagesize. And it is in the database. It would be a workaround.

    What do u think?

    TIA

    Monday, November 30, 2015 9:59 AM