3

我试过了:

ObjDTOleDBNFeIntegra.Rows(I)("[Cnpj Cpf]").ToString() //with brackets  
ObjDTOleDBNFeIntegra.Rows(I)("'Cnpj Cpf'").ToString() //with apostrophe  
ObjDTOleDBNFeIntegra.Rows(I)("Cnpj Cpf").ToString() //without anything  

我正在使用 VB.NET,但似乎无法识别此处带有撇号的注释。

我得到了每种情况的例外情况:(
Column '[Cnpj Cpf]' does not belong to table Table.失败) Column 'Cnpj Cpf' does not belong to table Table.    (失败) Column ''Cnpj Cpf'' does not belong to table Table.(失败)

当列名有空格时,我应该怎么做才能从 dataTable 中的字段中获取值?

4

1 回答 1

10

您是否检查过该认为它被称为什么?例如,它可能有下划线。遍历列并找出(抱歉,C# 中的示例):

foreach(DataColumn col in table.Columns) {
    Debug.WriteLine(col.ColumnName);
}

实际上,如果您在循环中执行该列,则使用该列会更快,因此我可能会使用以下内容:

DataColumn col = table.Columns["whatever"];
foreach(DataRow row in table.Rows) {
    Console.WriteLine(row[col]);
}
于 2010-03-08T19:13:56.127 回答