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=192.168.1.167")
        Dim cmd As New SqlCommand()
        constr.Open()
        constr.Close()
        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()
        da.Fill(ds)


        DataGridView1.DataSource = ds.Tables(0)

    End Sub
End Class