.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> Visual Studio >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Paging in a datagridview.

Posted By:satyapriyanayak       Posted Date: July 26, 2013    Points: 40    Category: Visual Studio    URL: http://www.dotnetspark.com  

Here we will know how to do paging in a datagridview.
 

Imports System.Data

Imports System.Data.OleDb

Public Class Form1

    Dim ConnectionString As String = System.Configuration.ConfigurationSettings.AppSettings("dsn")

    Dim con As OleDbConnection = New OleDbConnection(ConnectionString)

    Dim com As OleDbCommand

    Dim oledbda As OleDbDataAdapter

    Dim ds As DataSet

    Dim str As String

    Dim i As Integer

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Try

            con.Open()

            str = "select * from employee"

            com = New OleDbCommand(str, con)

            oledbda = New OleDbDataAdapter(com)

            ds = New DataSet

            oledbda.Fill(ds, i, 5, "employee")

            DataGridView1.DataSource = ds

            DataGridView1.DataMember = "employee"

            con.Close()

        Catch ex As Exception

            MsgBox(ex.Message)

        End Try

    End Sub

 

    Private Sub btn_Next_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_Next.Click

        i = i + 5

        If i > 23 Then

            i = 18

        End If

        ds.Clear()

        oledbda.Fill(ds, i, 5, "employee")

    End Sub

 

    Private Sub btn_Previous_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_Previous.Click

        i = i - 5

        If i <= 0 Then

            i = 0

        End If

        ds.Clear()

        oledbda.Fill(ds, i, 5, "employee")

    End Sub

End Class



     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend