Imports System.Data.SqlClient
Public Class Form5
Dim pagerows As Integer
Dim conn As New SqlConnection("Data Source=.;Initial catalog=sports;Integrated Security=True")
Private Sub count_rows()
Dim cmd As New SqlCommand("Select Count(*) From table1", conn)
conn.Open()
Dim count1 As Integer
count1 = Convert.ToString(cmd.ExecuteScalar)
pagerows = Math.Ceiling(count1 / 10)
Label3.Text = pagerows
conn.Close()
End Sub
Private Sub Form5_Load(sender As Object, e As EventArgs) Handles Me.Load
count_rows()
End Sub
Private Sub load_data()
Dim f1 As Integer = Label1.Text * 10 - 10 + 1
Dim t1 As Integer = Label1.Text * 10
Dim cmd As New SqlCommand("Select * From(Select Row_Number() Over (Order By sport) As rownumber,id,name,age,sport,points From table1)tablerow Where rownumber Between " & f1 & "And " & t1 & "", conn)
Dim da As New SqlDataAdapter
da.SelectCommand = cmd
Dim dt As New DataTable
da.Fill(dt)
DataGridView1.DataSource = dt
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Label1.Text = 1
load_data()
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
If Label1.Text < pagerows Then
Label1.Text = Label1.Text + 1
load_data()
End If
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
If Label1.Text > 1 Then
Label1.Text = Label1.Text - 1
load_data()
End If
End Sub
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
Label1.Text = pagerows
load_data()
End Sub
End Class
No comments:
Post a Comment