Click here to Skip to main content
15,884,176 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Please Help to This i am using VB.Net

My Table Have Data Like this

RegNO   Name   PaidAmount Class Section 
A100	AAAA	500        I	A
A200	BBBB	750        I	A
A100	AAAA	150        I	A
A300	CCCC	400        I	A
A400	DDDD	300        I	A
A100	AAAA	100        I	A
A300	cccc	350        I	A
A400	DDDD	450        I	A		


I Want Show DataGridview Like this

RegNO   Name   PaidAmount Class Section 
A100	AAAA	750       I	A
A200	BBBB	750       I	A
A300	CCCC	750       I	A
A400	DDDD	750       I	A


[edit]Code block added - OriginalGriff[/edit]
Posted
Updated 13-Jan-13 1:21am
v2
Comments
Sandeep Mewara 13-Jan-13 10:11am    
And what have you tried?
Navas Khanj 14-Jan-13 1:30am    
Dim strSQL6 As String = "SELECT Regno, SName, SUM(AmountPaid), FeeType, Class, Section FROM FeeTrans where class='" & cboClass.Text & "' and section='" & cboSection.Text & "' and FeeType='" & cboFeeType.Text & "' GROUP BY Regno, SName, FeeType, Class, Section"
Dim DaAp6 As New SqlDataAdapter(strSQL6, con)
Dim DSet6 As New DataTable
DaAp6.Fill(DSet6)

'========================================
With Me.DataGridView1

.Columns.Add("Regno", "RegNo")
.Columns.Add("SName", "Student Name")
.Columns.Add("AmountPaid", "Amount_Paid")
.Columns.Add("FeeType", "Fee Type")
.Columns.Add("Class", "Class")
.Columns.Add("Section", "Section")
.Columns(0).Width = 60
.Columns(1).Width = 150
.Columns(2).Width = 100
.Columns(3).Width = 100
.Columns(4).Width = 80
.Columns(5).Width = 80

' .AllowUserToAddRows = False
.EditMode = DataGridViewEditMode.EditProgrammatically
.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.TopCenter
End With

For Each dr As DataRow In DSet6.Rows
Me.DataGridView1.Rows.Add()
With Me.DataGridView1.Rows(Me.DataGridView1.Rows.Count - 1)
.Cells("Regno").Value = dr("Regno")
.Cells("SName").Value = dr("SName")
.Cells("Amount_Paid") = dr("AmountPaid")
.Cells("FeeType").Value = dr("FeeType")
.Cells("Class").Value = dr("Class")
.Cells("Section").Value = dr("Section")
End With
Next
My Error is Not Show Amount Filed in DatagridView.. Please tell me how to slove this proble.
Navas Khanj 13-Jan-13 10:53am    
Thanks..It's Working.. DataSet.. but when i use DataTable that time this Error Show This Line .Cells("Amount_Paid") = dr("AmountPaid") Error Is:(Column 'AmountPaid' does not belong to table .)

1 solution

The query you need is:
SQL
SELECT RegNO, Name, SUM(PaidAmount), Class, Section FROM myTable
GROUP BY RegNO, Name, Class, Section
 
Share this answer
 
Comments
Maciej Los 13-Jan-13 7:42am    
+5!

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