How to connect two tables in one datagridview

0 John Carlo Quinanola · March 23, 2015
i just want to ask if someone knows how to do this, im just a student and i have no idea what to study on to make this work.

i have sql server 2014 database with 5 tables created on it.

i want to display the information in two tables in one datagridview on the visual studio, but i cant..

thanks mate..

Post a Reply

Replies

Oldest  Newest  Rating
0 Eugene Botma · March 27, 2015
Here's the process for displaying data from a database in a gridview:

Get data from database (look up SqlCommand, SqlConnection, sql queries using union or join)
Convert data into usable format (look up SqlDataReader and SqlDataAdapter)
assign usable data to datagridview datasource.( this is literaly datagridview1.DataSource = myarrayofdataobjects; )

Now you know what to study to do this. But if you're a computer science or IT student and this is for a project, All of this should be in your handbook or course material. If it isn't, You should ask you lecturer about it.
0 mike richardson · March 24, 2015
You need to use UNION. But keep in mind you have to select the same number of columns from both tables.

SELECT This,That,Other FROM Table1
UNION
SELECT This2,That2,Other2 FROM Table2
  • 1

C#

107,235 followers
About

C# is an object-oriented language designed for improving the development of web applications.

Links
Moderators