Showing Records in the Data Grid when the button is clicked:

Imports System.Data.SqlClient
Public Class Form1
Dim cnn As New SqlConnection
Dim da1 As SqlDataAdapter
Dim cb1 As SqlCommandBuilder
Dim ds1 As New DataSet
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim cnnstr As String = "Data Source=USER;Initial
Catalog=BCA;Integrated Security=True"
cnn.ConnectionString = cnnstr
da1 = New SqlDataAdapter("select * from BCAStdInfo", cnn)
cb1 = New SqlCommandBuilder(da1)
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
da1.Fill(ds1)
DataGridView1.DataSource = ds1.Tables(0)
MsgBox("Reords Shown")
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
End Class

Note: Data is loaded in the Data Grid when the Show Records button is clicked instead of showing the data when the form is loaded. So the loading command is shifted to Button1_Click event.


When the Application is run the following screen shot is shown.



Previous Example<< Previous

Next >>Next Example

Our aim is to provide information to the knowledge


comments powered by Disqus




Footer1