Click here to Skip to main content
14,733,448 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am pulling data successfully from an Excel spreadsheet into a datatable, however when it gets to a column header that contains a period ".", I get the message,
Column 'Col.' does not belong to table.

and it converts Col. in datatable to Col#

What I have tried:

Dim v_Col As Integer
      Dim var As String
          v_Col = 0
          For Each r_item As DataRow In dt_city.Rows
              var = Trim(r_item.Item("Col."))
                  v_Col= Trim(r_item.Item("Col."))
              Catch exc0 As Exception
                  v_Ktn = 0
              End Try
      Catch ex As Exception
          MsgBox("column 'Col.' : " + ex.ToString)
      End Try
Updated 13-Jun-19 1:51am
CHill60 13-Jun-19 6:49am
This is a known problem when importing/exporting data between Excel and Access (for example) - show the code you are using to populate the datatable.
Of course you could always remove the period from the column header :-)
#realJSOP 13-Jun-19 6:53am
Can you see the column in DataTable.Columns using the debugger?

1 solution

I'd check the names of columns in a datatable object...

Try this:
For Each r_item As DataRow In dt_city.Rows
    For Each column As DataColumn In dt_city.Columns
        MsgBox(String.Format("{0} = {1}", column.ColumnName, r_item(column))
Member 14480131 13-Jun-19 7:56am
but i need to check this column name.
can u please explain this for me: Console.WriteLine("{0} = {1}", column.ColumnName, r_item(column))
Maciej Los 13-Jun-19 9:14am
Check updated answer.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900