Solved

How to display sql server data in a DataGridView

Posted on 2008-06-25
4
443 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Suggested Solutions

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

821 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