Wednesday, 12 October 2011

how to bind data to DataGridView in windows form

Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.DataSet
Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim constr As SqlConnection = New SqlConnection("User ID=sa; Password=Smsc408; Initial Catalog=adsonsms;Persist Security Info=True; Data Source=")
        Dim cmd As New SqlCommand()
        cmd = New SqlCommand("select * from testing with (nolock) ", constr)
        Dim da As New SqlDataAdapter, ds As New DataSet
        da = New SqlDataAdapter(cmd)
        ds = New DataSet()

        DataGridView1.DataSource = ds.Tables(0)

    End Sub
End Class