Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My CODE IS:
VB
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
       con.Close()

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

1 solution

You have not provided any alias to the SUM in sql query leading to no column named 'AmountPaid'. Modify to:
VB
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:
VB
.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)[^]
 
Share this answer
 
Comments
Navas Khanj 14-Jan-13 3:43am    
Thanks
Sandeep Mewara 14-Jan-13 5:04am    
Welcome.

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