c# .net Adsense ADO.NET Linq Viruses/security asp.net MVC JQuery Angular-js Node-js SEO Java C++ SQL API Networking vb.net .Net Css JavaScript Generics c#.Net entity framework HTML Website host Website Construction Guide HTTP tutorial W3C tutorial Web Services JSON Psychology Ionic framework Angular ReactJS Python Computer Android
vb.net

How to bind DataGridView in vb.net?

| | ASP , ASP-NET

In this articles describes how to bind DataGridView in vb.net. Here I am using SqlDataAdapter to fill dataset and then give dataset as DataSource for the grid.

Private Sub BindGrid()

Dim DbConnector As String = "Data Source=****;InitialCatalog=****; User Id=sa; Password=*****"

         Try

             Dim ds As New DataSet

             Using cn As New SqlConnection(DbConnector)

                cn.Open()

                Dim cmd As SqlCommand = cn.CreateCommand()

                cmd.CommandType = CommandType.Text

                cmd.CommandText = "Select * from dbo.tbl_Employee"

                cmd.ExecuteNonQuery()

                Dim da As SqlDataAdapter = New SqlDataAdapter(cmd)

                da.Fill(ds)

                cn.Close()

            End Using

            grid.DataSource = ds

         Catch ex As Exception

             Write(ex.ToString)

         End Try

    End Sub