Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
My CODE IS:
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 13-Jan-13 20:23pm
Edited 13-Jan-13 20:35pm
v2

1 solution

Rate this: bad
good
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)[^]
  Permalink  
Comments
Navas Khanj at 14-Jan-13 3:43am
   
Thanks
Sandeep Mewara at 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)

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 432
1 sanket saxena 355
2 Abhinav S 258
3 OriginalGriff 235
4 CPallini 205
0 Sergey Alexandrovich Kryukov 8,704
1 OriginalGriff 5,000
2 Peter Leow 3,839
3 Maciej Los 3,535
4 Er. Puneet Goel 3,107


Advertise | Privacy | Mobile
Web03 | 2.8.140415.2 | Last Updated 14 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid