Question

I have tried:

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

I'm using VB.NET, but comments with apostrophes in here don't seem to be identified.

And I get the exceptions for each case:
Column '[Cnpj Cpf]' does not belong to table Table. (fail) Column 'Cnpj Cpf' does not belong to table Table.    (fail) Column ''Cnpj Cpf'' does not belong to table Table. (fail)

What should I do in order to ger a value from a field in a dataTable when the column name has spaces ?

Was it helpful?

Solution

Have you checked what the column thinks it is called? It might have underscores, for example. Loop over the columns and find out (sorry, examples in C#):

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

Actually, it is faster to use the column if you are doing it in a loop, so I might use something like:

DataColumn col = table.Columns["whatever"];
foreach(DataRow row in table.Rows) {
    Console.WriteLine(row[col]);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top