Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
How can I implement paging in datagridview for windows forms ?
Posted
Comments
ohm.ronak 30-Dec-12 7:00am    
ublic Class Forms


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If (IsNumeric(txtname.Text.ToString) Or txtname.Text = "" Or IsNumeric(father.Text.ToString) Or father.Text = "") Then
MessageBox.Show("only string is allowed")
ElseIf (Not IsNumeric(fees.Text.ToString) Or fees.Text = "") Then
MessageBox.Show("only numeric is allowed")
ElseIf (Not (datetime.Value.Year <= Today.Year - 5)) Then
MessageBox.Show("student must be five years old")
Else
Try
Dim dt As New DataTable
Dim conn As SqlClient.SqlConnection
conn = New SqlClient.SqlConnection("Data Source=ADMIN-PC;Initial Catalog=STUDENT MANAGMENT;User ID=sa;Password=sys")
Dim comm As New SqlClient.SqlCommand
comm.Connection = conn
comm.CommandType = CommandType.StoredProcedure
comm.CommandText = "insertandselect"
comm.Parameters.AddWithValue("@name", txtname.Text)
comm.Parameters.AddWithValue("@bdate", datetime.Text)
comm.Parameters.AddWithValue("@Adresscity", address.Text)
comm.Parameters.AddWithValue("@fathername", father.Text)
comm.Parameters.AddWithValue("@occp", occupation.Text)
comm.Parameters.AddWithValue("@fees", fees.Text)
comm.Parameters.AddWithValue("@remarks", remark.Text)
Dim sda As SqlClient.SqlDataAdapter
sda = New SqlClient.SqlDataAdapter(comm)
sda.Fill(dt)
DataGridView1.DataSource = dt




MessageBox.Show("admission successfully")
Catch ex As Exception
MessageBox.Show("admission unsuccessfull")
End Try
End If


End Sub

Private Sub Forms_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Try
Dim dt As New DataTable
Dim conn As SqlClient.SqlConnection
conn = New SqlClient.SqlConnection("Data Source=ADMIN-PC;Initial Catalog=STUDENT MANAGMENT;User ID=sa;Password=sys")
conn.Open()
Dim comm As SqlClient.SqlCommand
comm = New SqlClient.SqlCommand("select * from CITY_NAME_MASTER_TABLE", conn)
Dim sda As SqlClient.SqlDataAdapter
sda = New SqlClient.SqlDataAdapter(comm)
sda.Fill(dt)
city.DisplayMember = "CITY_NAME"
city.ValueMember = "CITY_ID"
city.DataSource = dt


Catch ex As Exception

End Try
Try
Dim dt As New DataTable
Dim conn As SqlClient.SqlConnection
conn = New SqlClient.SqlConnection("Data Source=ADMIN-PC;Initial Catalog=STUDENT MANAGMENT;User ID=sa;Password=sys")
Dim comm As New SqlClient.SqlCommand
Dim sda As SqlClient.SqlDataAdapter
comm.Connection = conn
comm.CommandType = CommandType.StoredProcedure
comm.CommandText = "select_datafrom_studentmaster"
sda = New SqlClient.SqlDataAdapter(comm)
sda.Fill(dt)
DataGridView1.DataSource = dt


Catch ex As Exception

End Try


End Sub

Private Sub top_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles top.Click
Try
Dim dt As New DataTable
Dim conn As SqlClient.SqlConnection
conn = New SqlClient.SqlConnection("Data Source=ADMIN-PC;Initial Catalog=STUDENT MANAGMENT;User ID=sa;Password=sys")
Dim comm As New SqlClient.SqlCommand
Dim sda As SqlClient.SqlDataAdapter
comm.Connection = conn
comm.CommandType = CommandType.StoredProcedure
comm.CommandText = "selecttop"
sda = New SqlClient.SqlDataAdapter(comm)

1 solution

Dear Friend,

Following links will help you out:-

http://www.dotnetspider.com/forum/166415-DataGridview-Paging-windows-forms-using-VB-NET.aspx[^]

http://www.vb-tips.com/PageDataGridView.aspx[^]

http://vbcity.com/forums/t/162313.aspx[^]

Don''t forget to mark this as your answer if it helps you out.

thanks
 
Share this answer
 

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