How to display sql server data in a DataGridView

I can create a tableadapter stored procedure or sql query that joins columns from 2 tables.
How can I  display  the sql server data in a DataGridView?

Sample code would be appreciated.

Who is Participating?
Jorge PaulinoConnect With a Mentor IT Pro/DeveloperCommented:
I don't understoud if you already have the two tables joined (using INNER JOIN query) but for fill the datagridview you can do something like this:
Imports System.Data.SqlClient
    Dim da As SqlDataAdapter
    Dim ds As DataSet
    Dim connection As New SqlConnection(myConnectionString)
    Dim SQL As String = "SELECT * FROM myTable"
    da = New SqlDataAdapter(SQL, connection)
    ds = New DataSet
    da.Fill(ds, "myTable")
    Me.DataGridView1.DataSource = ds.Tables("myTable")
    connection = Nothing

Open in new window

dave_skyAuthor Commented:
Thanks for the response.

Your sample code refers to SqlDataAdapter...
Will it work if I create the INNER JOIN with a TableAdapter query?
Jorge PaulinoIT Pro/DeveloperCommented:
It should work!
dave_skyAuthor Commented:
Thanks for your help!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.