fill datagrid

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

Accepted Solution

razorback041 earned 500 total points
ID: 16312778
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

Expert Comment

ID: 16312785
forgot to change the example to your names..sorry

Expert Comment

ID: 16315482
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses
Course of the Month13 days, 22 hours left to enroll

809 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