Solved

How to display sql server data in a DataGridView

Posted on 2008-06-25
4
440 Views
Last Modified: 2012-06-21
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
Comment
Question by:dave_sky
  • 2
  • 2
4 Comments
 
LVL 48

Accepted Solution

by:
jpaulino earned 500 total points
ID: 21868083
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
 

Author Comment

by:dave_sky
ID: 21868220
Thanks for the response.

Your sample code refers to SqlDataAdapter...
Will it work if I create the INNER JOIN with a TableAdapter query?
0
 
LVL 48

Expert Comment

by:jpaulino
ID: 21868329
It should work!
0
 

Author Comment

by:dave_sky
ID: 21890767
Thanks for your help!
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

760 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

18 Experts available now in Live!

Get 1:1 Help Now