Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
Table1
RegNO Name PaidAmount Class Section
A100 AAAA 750 I A
A200 BBBB 750 I B
A300 CCCC 750 I A
A400 DDDD 750 I A
 
Table2
RegNO Name Amount Class Section
A100 AAAA 1500 I A
A200 BBBB 1500 I B
A300 CCCC 1800 I A
A400 DDDD 1500 I A
 

I want DatagridView Like This
 
RegNO Name PaidAmount Amount Class Section
A100 AAAA 750 1500 I A
A200 BBBB 750 1500 I B
A300 CCCC 750 1800 I A
A400 DDDD 750 1500 I A
 
Please Help Me.. for this problem..
Posted 13-Jan-13 23:25pm

1 solution

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

Solution 1

You just need to write a query that combines the data of two table tables and show it as datasource of your grid.
 
There is other wya to retrieve both tables separately on front end and then combine - but I would not suggest this as it would be much easier to combine them at DB level.
 
Sample:
SELECT 
   t1.col1, t1.col2, t2.col3
FROM 
   table1 t1
INNER JOIN
   table2 t2
ON t1.RegNO = t2.RegNO
Result set would have combined data that can directly be set as source for grid.
  Permalink  
Comments
Navas Khanj at 14-Jan-13 11:46am
   
I am Using this Code..
Dim strSQL6 As String = "SELECT Fees_Transaction.Regno, Fees_Transaction.ST_Name, SUM(Fees_Transaction.Amount_Paid) As TotalAmountPaid, Fees_Transaction.FeeType, Fees_Transaction.Class, Fees_Transaction.Section, FeesMaster.FeeAmount FROM Fees_Transaction INNER JOIN FeesMaster ON Fees_Transaction.Regno = FeesMaster.Regno WHERE Fees_Transaction.class='" & cboClass.Text & "' and Fees_Transaction.section='" & cboSection.Text & "' and Fees_Transaction.FeeType='" & cboFeeType.Text & "' GROUP BY Fees_Transaction.Regno, Fees_Transaction.ST_Name, Fees_Transaction.Class, Fees_Transaction.Section, Fees_Transaction.FeeType,FeesMaster.FeeAmount"
.. But DataGridView Display twice . how to slove it.. Please tell me.
Sandeep Mewara at 14-Jan-13 13:04pm
   
What do you mean by display twice? Not clear.
Navas Khanj at 14-Jan-13 13:08pm
   
DataGridView1.Rows.Clear()
DataGridView1.Columns.Clear()

Dim strSQL7 As String = "SELECT Fees_Transaction.Regno,Fees_Transaction.ST_Name,Sum(Fees_Transaction.Amount_Paid)as TotalAmountPaid,FeesMaster.FeeAmount,Fees_Transaction.FeeType,Fees_Transaction.Class,Fees_Transaction.Section FROM Fees_Transaction INNER JOIN FeesMaster ON Fees_Transaction.Regno=FeesMaster.Regno WHERE Fees_Transaction.class='" & cboClass.Text & "' and Fees_Transaction.section='" & cboSection.Text & "' and Fees_Transaction.FeeType='" & cboFeeType.Text & "' GROUP BY Fees_Transaction.Regno,Fees_Transaction.ST_Name,Fees_Transaction.FeeType,Fees_Transaction.Class,Fees_Transaction.Section,FeesMaster.FeeAmount"
Dim DaAp7 As New SqlDataAdapter(strSQL7, con)
Dim DSet7 As New DataTable
DaAp7.Fill(DSet7)
'========================================
With Me.DataGridView1
.Columns.Add("Regno", "RegNo")
.Columns.Add("ST_Name", "Student Name")
.Columns.Add("Amount_Paid", "Amount Paid")
.Columns.Add("Remaining", "Remaining")
.Columns.Add("TotalAmt", "Total Amount")
.Columns.Add("FeeType", "Fee Type")
.Columns.Add("Class", "Class")
.Columns.Add("Section", "Section")
.Columns(0).Width = 85
.Columns(1).Width = 250
.Columns(2).Width = 150
.Columns(3).Width = 150
.Columns(4).Width = 140
.Columns(5).Width = 150
.Columns(6).Width = 90
.Columns(7).Width = 90
' .AllowUserToAddRows = False
.EditMode = DataGridViewEditMode.EditProgrammatically
.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.TopCenter
End With
 
For Each dr As DataRow In DSet7.Rows
Me.DataGridView1.Rows.Add()
With Me.DataGridView1.Rows(Me.DataGridView1.Rows.Count - 1)
.Cells("Regno").Value = dr("Regno")
.Cells("ST_Name").Value = dr("ST_Name")
.Cells("Amount_Paid").Value = dr("TotalAmountPaid")
.Cells("TotalAmt").Value = dr("FeeAmount")
.Cells("FeeType").Value = dr("FeeType")
.Cells("Class").Value = dr("Class")
.Cells("Section").Value = dr("Section")
End With
Next
i send Code for U..
Navas Khanj at 14-Jan-13 13:08pm
   
This Code DataGridView Display 2 time .
Navas Khanj at 14-Jan-13 13:14pm
   
Table1 Name is (Fees_Transaction)
 
RegNO ST_Name Amount_Paid Class Section
A100 AAAA 750 I A
A200 BBBB 500 I B
A300 CCCC 800 I A
A400 DDDD 450 I A

Table2 Name is (FeesMaster)

RegNO SName TotalAmount Class Section
A100 AAAA 1500 I A
A200 BBBB 1500 I B
A300 CCCC 1500 I A
A400 DDDD 1500 I A

 
I Want DataGridView Like This
 

RegNO ST_Name PaidAmount TotalAmount Class Section
A100 AAAA 750 1500 I A
A200 BBBB 500 1500 I B
A300 CCCC 800 1500 I A
A400 DDDD 450 1500 I A

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

  Print Answers RSS
0 OriginalGriff 216
1 CPallini 195
2 BillWoodruff 180
3 Maciej Los 165
4 Kornfeld Eliyahu Peter 140


Advertise | Privacy | Mobile
Web04 | 2.8.141015.1 | Last Updated 14 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