Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 452
  • Last Modified:

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.

Thanks
0
dave_sky
Asked:
dave_sky
  • 2
  • 2
1 Solution
 
jpaulinoCommented:
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

0
 
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?
0
 
jpaulinoCommented:
It should work!
0
 
dave_skyAuthor Commented:
Thanks for your help!
0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now