get a range of data in Visual Basic

1

I would like to obtain a range of data in the visual basic function, that is to say I have 1000 data but I only want to obtain the amount of 100 data, this is my code in Visual Basic and I would like to know how to obtain the amount of data, in this way I get all the data that I have stored in sql but I would like to only get a certain amount

 Public Function Datos(ByVal NoFact As String) As DataTable

    Try
        Dim dtResultado As New DataTable
        Dim sqladap As New SqlClient.SqlDataAdapter()


        If Todas = True Then
            Dim sqlcon As New SqlClient.SqlCommand("SP_Example")
            sqlcon.CommandType = CommandType.StoredProcedure
            sqlcon.Connection = con
            con.Open()
            sqladap.SelectCommand = sqlcon
            sqladap.Fill(dtResultado)

            If dtResultado.Rows.Count > 0 Then
                Return dtResultado
            Else
                Return New DataTable

            End If
    
asked by Daniel 08.02.2018 в 22:49
source

1 answer

0

In the Query you can define the amount of data to obtain:

Dim query As String = "select top 100 * from table"
Dim sqlcon As New SqlClient.SqlCommand(query)

If you use a Stored Procedure, simply modify it using "select top 100 * from table" to get only the data you want.

   Dim sqlcon As New SqlClient.SqlCommand("nombre_stored_procedure")
            sqlcon.CommandType = CommandType.StoredProcedure
            sqlcon.Connection = con
            con.Open()
        ...
        ...
    
answered by 08.02.2018 в 23:11