Tuesday, May 15, 2012

VB.NET SQL Connection fill GridView

     Imports system.data.sqlclient
     Imports system.data

         Dim cn As New SqlConnection
        Dim sql As String
        Dim ds As New DataSet
        Dim da As New SqlDataAdapter
        cn = New SqlConnection("server=localhost;database=NLAB 2012-2013;integrated security=true")
        sql = "select * from mainmaster"
        Dim cm As New SqlCommand(sql, cn)
        da = New SqlDataAdapter(cm)
        da.Fill(ds)
        GridView1.DataSource = ds.Tables(0)
        GridView1.DataBind()

No comments: