Solved

How to display sql server data in a DataGridView

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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Suggested Solutions

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
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.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

810 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