我正在使用此代码向Datagridview
添加分页。
我想要的是如何添加Button进入第一页并添加另一个Button进入最后一页?
这是代码:
Imports System.Data.Odbc ' using ODBC namespace
Public Class Form1
Dim conn As OdbcConnection ' declare for our connection
Dim Da As OdbcDataAdapter ' declare for Data Adapter
Dim Ds As DataSet ' declare for dataset
Dim Filter As Integer ' for max value to show the data/paging
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
' load data button
' you must have a Database before
' i use MySQL database for this application
' i'll create connection using Odbc
' set connection using ODBC
conn = New OdbcConnection("DSN=k13new;MultipleActiveResultSets=True")
' create SQL query to show data from MySQL Database
Dim sql As String = "SELECT * FROM biodata order by idsiswa"
Da = New OdbcDataAdapter(sql, conn)
Ds = New DataSet
' open connection
conn.Open()
Da.Fill(Ds, Filter, 15, "biodata")
' max Count of data will show at one page is 15
' close connection
conn.Close()
DataGridView1.DataSource = Ds
DataGridView1.DataMember = "biodata"
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
' prev button
Filter = Filter - 15
If Filter <= 0 Then
Filter = 0
End If
Ds.Clear()
Da.Fill(Ds, Filter, 15, "biodata")
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
' next button
Filter = Filter + 15
Ds.Clear()
Da.Fill(Ds, Filter, 15, "biodata")
End Sub
End Class