Click here to Skip to main content
13,294,516 members (60,209 online)
Rate this:
Please Sign up or sign in to vote.
See more:
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
        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
            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

My Error is AMOUNTPIAD Filed not show DatagridView.. Erros is : Column 'AmountPaid' does not belong to table . Please Help Me
Posted 13-Jan-13 21:23pm
Updated 13-Jan-13 21:35pm

1 solution

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

Solution 1

You have not provided any alias to the SUM in sql query leading to no column named 'AmountPaid'. Modify to:
Dim strSQL6 As String = "SELECT  Regno, SName, SUM(AmountPaid) as TotalAmountPaid, FeeType, Class, Section FROM  FeeTrans where...

Post this, bind the new column name of dataset to your grid as:
.Cells("Amount_Paid") = dr("TotalAmountPaid")

P.S.: I also see that the syntax of adding new columns seems incorrect. Add method with two parameters tells to add column of a given name and type.
Refer: MSDN: DataColumnCollection.Add Method (String, Type)[^]
Navas Khanj 14-Jan-13 3:43am
Sandeep Mewara 14-Jan-13 5:04am

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 |
Web03 | 2.8.171207.1 | Last Updated 14 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