Bob Gatto

Bob Gatto

  • 1.6k
  • 44
  • 7k

How do I combine 2 tables into 1 datagridview?

Dec 7 2020 10:38 PM
I have 2 tables. One is a list of categories created with the following code:
  1. CREATE TABLE [dbo].[Groups] (  
  2.     [groupname] NVARCHAR (50) NULL,  
  3.     [Id] INT IDENTITY (1, 1) NOT NULL,  
  4.     PRIMARY KEY CLUSTERED ([Id] ASC)  
  5. ); 
and the other is for storing various data and was created with this:
  1. CREATE TABLE [dbo].[Passwords] (  
  2.     [title]    NVARCHAR (100) NULL,  
  3.     [username] NVARCHAR (25)  NULL,  
  4.     [password] NVARCHAR (25)  NULL,  
  5.     [url]      NVARCHAR (150) NULL,  
  6.     [notes]    NVARCHAR (MAXNULL,  
  7.     [group_no] INT            NULL,  
  8.     [Id]       INT            IDENTITY (1, 1) NOT NULL,  
  9.     PRIMARY KEY CLUSTERED ([Id] ASC)  
  10. ); 
Now in table #2 it is possible to have more than one of the same group_no. Also table1.Id = table2.group_no. What I'm looking to do is display a list (maybe a datagridview) that displays the name of the group (table1.groupnane) and the total number of records in table 2 related to that group (table1.Id = table2.group_no).
 
I think there's some kind of SQL statement but I just can't place it. I'm using c#. 
 
Is there anyone out there who can help? Thanks.

Answers (2)