fill datagrid

Posted on 2006-03-28
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
Question by:VBdotnet2005
    LVL 5

    Accepted Solution

    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
    LVL 5

    Expert Comment

    forgot to change the example to your names..sorry
    LVL 6

    Expert Comment

    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"

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Join & Write a Comment

    This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
    It’s quite interesting for me as I worked with Excel using for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now