DataGridView显示错误 [英] DataGridView Display Error

查看:89
本文介绍了DataGridView显示错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码是:

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()



我的错误是AMOUNTPIAD归档不显示DatagridView .. Erros是:列''AmountPaid''不属于表。请帮助我


My Error is AMOUNTPIAD Filed not show DatagridView.. Erros is : Column ''AmountPaid'' does not belong to table . Please Help Me

推荐答案

在sql查询中没有为SUM提供任何别名,导致没有名为AmountPaid的列。修改为:

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")



< b:我还看到添加新列的语法似乎不正确。添加带有两个参数的方法告诉添加给定名称和类型的列。

参考: MSDN:DataColumnCollection.Add方法(字符串,类型) [ ^ ]


这篇关于DataGridView显示错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆