Click here to Skip to main content
15,885,365 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to Merge Two table and Show to DAtaGridViw
Posted
Comments
fjdiewornncalwe 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..

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.
 
Share this answer
 
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.

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.
 
Share this answer
 
Comments
Sandeep Mewara 21-Jan-13 11:58am    
Good suggestion. 5.
Abhinav S 21-Jan-13 12:00pm    
Thank you.
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: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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900