We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now


fill datagrid

VBdotnet2005 asked
Medium Priority
Last Modified: 2010-04-23
i am working on VB.NET windows application.
In my windows form i have a one Datagrid
I want to  fill  this datagrid from my database, called "Sample1". How can I accomplish this task?  I created data connection in Server Explorer. Sample1.dbo - Tables  ---> Addresses
Watch Question

Private Const queryString As String = _
    "query string for db goes here"
Private Const myConn As String = _
    "connection string goes here"

' The DataSet that holds the data.
Private myDataSet As DataSet

' Load the data.
Private Sub Form1_Load(ByVal sender As Object, ByVal e As _
    System.EventArgs) Handles MyBase.Load
    Dim da As SqlDataAdapter

    ' Create the SqlDataAdapter.
    da  = New SqlDataAdapter(queryString, _

    ' Map Table to Contacts.
    da.TableMappings.Add("Table", "Name")

    ' Fill the DataSet.
    myDataSet = New DataSet()

    ' Bind the DataGrid control to the Contacts DataTable.
    dg.SetDataBinding(myDataSet, "Name")
End Sub

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
forgot to change the example to your names..sorry

Or, using the Microsoft Data Access Application block...

Dim DS as New Dataset

SqlHelper.FillDataset(ConnectionString, CommandType.Text, "SELECT * FROM urTable", DS, New String() {"Table Name"})
Me.datagrid1.DataSource = DS
Me.datagrid1.DataMember = "Exceptions"
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.