Click here to Skip to main content
12,882,820 members (37,344 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: VB VB.NET
How to Merge Two table and Show to DAtaGridViw
Posted 21-Jan-13 5:23am
Comments
Marcus Kramer 21-Jan-13 11:25am
   
You need to give us some more information. What do the two tables look like? Do they contain the same structure?
Navas Khanj 21-Jan-13 11:59am
   
Dim strSQL4, strSQL5 As String
con.Open()
strSQL4 = "Select Regno, ST_Name, SUM(Amount_Paid) as Amount_Paid,Class,Section FROM Fees_Transaction WHERE class='" & cboClass.Text & "' GROUP By Regno, ST_Name, Class, Section"
strSQL5 = "Select Regno, SUM(FeeAmount) as FeeAmount FROM FeesMaster WHERE class='" & cboClass.Text & "' GROUP By Regno"
Dim DaAp4 As New SqlDataAdapter(strSQL4, con)
Dim DSet4 As New DataSet
DaAp4.Fill(DSet4, "Fees_Transaction")
Dim DaAp5 As New SqlDataAdapter(strSQL5, con)
Dim DSet5 As New DataSet

DSet4.Merge(DSet5, True)
DataGridView2.DataSource = DSet4.Tables(0)
con.Close()
I want Merge this two table please tell me how can i do..
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

What have you tried so far?

Based on the data connection or when you want, it can be done in multiple ways.
You can have combined data
- while fetching from database.
- in business layer/front end
- connect the datasets using a relation and display in grid

Pick the one that suits you and post specific issue if you face any.
  Permalink  
Comments
Abhinav S 21-Jan-13 11:39am
   
5!
Sandeep Mewara 21-Jan-13 11:58am
   
Thanks
Navas Khanj 21-Jan-13 11:59am
   
Dim strSQL4, strSQL5 As String
con.Open()
strSQL4 = "Select Regno, ST_Name, SUM(Amount_Paid) as Amount_Paid,Class,Section FROM Fees_Transaction WHERE class='" & cboClass.Text & "' GROUP By Regno, ST_Name, Class, Section"
strSQL5 = "Select Regno, SUM(FeeAmount) as FeeAmount FROM FeesMaster WHERE class='" & cboClass.Text & "' GROUP By Regno"
Dim DaAp4 As New SqlDataAdapter(strSQL4, con)
Dim DSet4 As New DataSet
DaAp4.Fill(DSet4, "Fees_Transaction")
Dim DaAp5 As New SqlDataAdapter(strSQL5, con)
Dim DSet5 As New DataSet

DSet4.Merge(DSet5, True)
DataGridView2.DataSource = DSet4.Tables(0)
con.Close()
I want Merge this two table please tell me how can i do..
Sandeep Mewara 21-Jan-13 12:03pm
   
Both looks like having RegNo. Use that as a JOIN condition if you are planning to collate data at DB level.
For frontend, you would need two for loops cascaded, one for each datatable. Check the data for the same regno and then add it.

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

You should keep your processing on the database side.
Merge the tables using UNION or JOIN, return the data to your C# code and then assign to the data grid.
  Permalink  
Comments
Sandeep Mewara 21-Jan-13 11:58am
   
Good suggestion. 5.
Navas Khanj 21-Jan-13 11:59am
   
Dim strSQL4, strSQL5 As String
con.Open()
strSQL4 = "Select Regno, ST_Name, SUM(Amount_Paid) as Amount_Paid,Class,Section FROM Fees_Transaction WHERE class='" & cboClass.Text & "' GROUP By Regno, ST_Name, Class, Section"
strSQL5 = "Select Regno, SUM(FeeAmount) as FeeAmount FROM FeesMaster WHERE class='" & cboClass.Text & "' GROUP By Regno"
Dim DaAp4 As New SqlDataAdapter(strSQL4, con)
Dim DSet4 As New DataSet
DaAp4.Fill(DSet4, "Fees_Transaction")
Dim DaAp5 As New SqlDataAdapter(strSQL5, con)
Dim DSet5 As New DataSet

DSet4.Merge(DSet5, True)
DataGridView2.DataSource = DSet4.Tables(0)
con.Close()
I want Merge this two table please tell me how can i do..
Abhinav S 21-Jan-13 12:00pm
   
Thank you.
Abhinav S 21-Jan-13 12:01pm
   
Just use a UNION between the two queries. Union requires number of columns and their types should match in the two queries.
So add blanks for the missing Class, Section in the second row.
Navas Khanj 21-Jan-13 12:30pm
   
UNION command show one by one Record.. but i want Like this
Regno ST_Name Amount_Paid Class Section FeeAmount

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.170422.1 | Last Updated 21 Jan 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100