Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello guys i am developing some project using vb.net 2010 i have 1 table with12 columns. i have 1 datagridview in one vb form, and on the data gridview1 all data is populated from ms-sql database well...its work fine. but my question is i wont to populate/see only 10 records, if it is possible users click next button and datagrid will show the next 10 records. how can i do this,

here is my code to populate the data
private Sub MDIParent1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        
        GetData("select [ID],[DocId],[Description]      ,[Address]      ,[NoOfPages]      ,[SendOrReceived]      ,[SentDate]      ,[ReceivedDate]      ,[ForwardedWorkingUnit]      ,[Attachements]      ,[ForwardedDate]      ,[ReceivedBy]      ,[LetterWrittenDate]      ,[DocPath]  FROM [Data].[dbo].[EraDms]ORDER BY Id DESC")

      
        Me.DataGridView1.DataSource = Me.bindingSource1

 
    End Sub


VB
Private Sub GetData(ByVal selectCommand As String)

        Try
           
            Dim connectionString As String = _
                "Server=servername;Network Library=DBMSSOCN;Initial Catalog=Data;User ID=sa;Password=P@ssw0rd;"

            ' Create a new data adapter based on the specified query.
            Me.dataAdapter = New SqlDataAdapter(selectCommand, connectionString)

            ' Create a command builder to generate SQL update, insert, and
            ' delete commands based on selectCommand. These are used to
            ' update the database.
            Dim commandBuilder As New SqlCommandBuilder(Me.dataAdapter)

            ' Populate a new data table and bind it to the BindingSource.

            table.Locale = System.Globalization.CultureInfo.InvariantCulture
            Me.dataAdapter.Fill(table)
            Me.bindingSource1.DataSource = table

            ' Resize the DataGridView columns to fit the newly loaded content.
            Me.DataGridView1.AutoResizeColumns( _
                DataGridViewAutoSizeColumnsMode.ColumnHeader)

            DataGridView1.Columns(0).Visible = False
        Catch ex As SqlException

        End Try

    End Sub
Posted

1 solution

 
Share this answer
 
Comments
Thanks7872 16-Aug-13 5:34am    
↑voted as it is very straight forward.
TrushnaK 16-Aug-13 5:47am    
thnx
Thanks7872 16-Aug-13 5:47am    
You are welcome. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900