微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

'找不到名为 Brand_ID 的列参数名称:columnName'

如何解决'找不到名为 Brand_ID 的列参数名称:columnName'

尝试从数据网格中获取值,同时首先检查该值是否确实存在给了我一个问题,即该列不存在,即使它存在。

这是绑定代码

 dtBrands = fnGetmmBranchBrand(0)
  If dtBrands IsNot nothing Then 'if the datatable exists
            dvBrands.Table = dtBrands  'bind the datatable
            If dvBrands.Table.Columns.Contains("Branch_ID") Then
                dvBrands.RowFilter = "Branch_ID=" & intBranch_ID 'filter out all the records that aren't supposed to be in
            End If
            blProcessEvents = True 'set the semaphore to true here so that when the dg is populated the rows get filtered out of the comboBox
            dgBrands.DataSource = dvBrands  'Fill the datagrid with the dv
end if

填充 dv 会按预期触发行添加事件处理程序

Private Sub dgBrands_RowsAdded(sender As Object,e As DataGridViewRowsAddedEventArgs) Handles dgBrands.RowsAdded
            If blProcessEvents = True Then
            'when a row is added count through all the rows that are in the datagrid
            'and then refresh the results in the cbo based on the ones it didn't find in the dg
            Dim intIndex As Integer = 0 'this is a counter
            Dim strMasterFilter As String = "" 'clear the search string first

For intIndex = 0 To dgBrands.Rows.Count - 1 'count through all the rows in the dg
                If dgBrands.Rows(intIndex).Cells("Brand_ID").Value IsNot nothing Then 'check if Brand_ID value exists in the datagrid
                    Dim intBrand_ID As Integer = dgBrands.Rows(intIndex).Cells("Brand_ID").Value 'grab the Brand_ID value and store it in a variable
               end if
Next

但随后“如果 dgBrands.Rows(intIndex).Cells("Brand_ID").Value IsNot nothing Then”错误地说:'找不到名为 Brand_ID 的列。 参数名称:columnName' 这对我来说毫无意义,因为 Column 拼写正确, its part of the dv that is its datasource

最奇怪的是 MessageBox.Show(dgBrands.Columns.Count) = 1!,由于某种原因只显示了“ID”列.....

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?