找不到类型为“DataColumn”的默认成员。 [英] No default member found for type 'DataColumn'.
问题描述
您好,
我正在尝试浏览DataTable并找出哪个行的帐号与txtBx相同。
但我收到错误 - 找不到类型'DataColumn'的默认成员。
if语句发生错误。
Hello,
I am trying to go through a DataTable and to find out which row has a AccountNo the same as the txtBx.
But I am getting an error - No default member found for type 'DataColumn'.
The error is occurring on the if statement.
Dim COUNT As Integer = dt.Rows.Count
For Each DataColumn In dt.Columns
For r As Integer = 0 To COUNT - 1
If DataColumn("AccountNo") = FrmSearch.txtCustID1.Text Then
Dim output As String = DataColumn.ToString().ElementAt(r)
dtValue.Rows.Add(output)
End If
Next
Next
任何建议表示赞赏:)
干杯,
Glen
Any suggestions are appreciated :)
Cheers,
Glen
推荐答案
尝试如下...
Try like below...
For Each row As DataRows In dt.Rows
在循环内使用 row
变量。
编译器不知道字段中的值是字符串,所以你需要告诉它。
或者,您可以使用框架来为你做的工作。有点像
The compiler doesn't know that the value in the field is a string, so you need to tell it.
Alternatively, you could use the framework to do the work for you. Something along the lines of
System.Data.DataView dv = new System.Data.DataView ( dt ) ;
dv.RowFilter = "AccountNo='" + FrmSearch.txtCustID1.Text + "'" ;
foreach ( System.Data.DataRowView dr in dv )
{
...
}
(或等效的VB.net)
DataView将只返回您要求的行。
(or the VB.net equivalent)
The DataView will return only the row(s) that you asked for.
For r As Integer = 0 To COUNT - 1
For Each column As DataColumn In dt.Columns
If column("AccountNo") = FrmSearch.txtCustID1.Text Then
Dim output As String = DataColumn.ToString().ElementAt(r)
dtValue.Rows.Add(output)
End If
Next
改变For Each为dt.Rows的作用是什么of dt.Columns。
What worked was to change the For Each to be dt.Rows instead of dt.Columns.
这篇关于找不到类型为“DataColumn”的默认成员。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!