Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
How to Merge Two table and Show to DAtaGridViw
Posted 21-Jan-13 5:23am
Comments
Marcus Kramer at 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 at 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 at 21-Jan-13 11:39am
   
5!
Sandeep Mewara at 21-Jan-13 11:58am
   
Thanks
Navas Khanj at 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 at 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 at 21-Jan-13 11:58am
   
Good suggestion. 5.
Abhinav S at 21-Jan-13 12:00pm
   
Thank you.
Navas Khanj at 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 at 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 at 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
0 OriginalGriff 534
1 Gihan Liyanage 298
2 ChintanShukla 295
3 RyanDev 250
4 Richard Deeming 250
0 Sergey Alexandrovich Kryukov 8,906
1 OriginalGriff 7,771
2 CPallini 2,603
3 Richard MacCutchan 2,121
4 Abhinav S 1,928


Advertise | Privacy | Mobile
Web04 | 2.8.140827.1 | Last Updated 21 Jan 2013
Copyright © CodeProject, 1999-2014
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