1

I have some problem with the function GetOrdinal coming from the OleDb.DataReader. In my table, I have columns named with some space. I tried to call it with some [ ]:

Dim dr as System.Data.OleDb.OleDbDataReader dr.GetOrdinal("[Nom truc]")

but it's telling me : "IndexOutOfRangeException"

I can't change the name of the field. The type of my base is accdb. In Microsoft Access, my query is working.

Sorry for my poor english, I'm an France girl :)

Thank you in advance!

MlleStrife
  • 43
  • 1
  • 10

1 Answers1

0

You should remove the brackets:

'dr.GetOrdinal("[Nom truc]")
dr.GetOrdinal("Nom truc")
LarsTech
  • 80,625
  • 14
  • 153
  • 225
  • It's not working because I am using the request to set up an OleDbCommand:
    `Dim c as System.Data.OleDb.OleDbCommand("Select [nom truc] from machin")
    c.ExecuteReader()`
    Without the brackets I have a syntax exception. So I tried to put the brackets in c and remove then from the dr.GetOrdinal but it return nothing.
    – MlleStrife Apr 05 '16 at 07:31
  • @MlleStrife You keep the brackets in your sql, you lose the brackets in your GetOrdinal function. If it returns nothing, then you have no data. – LarsTech Apr 05 '16 at 13:19
  • Thanks a lot, it's working! :) I made a mistake in my field name when I tried to print the return of GetOrdinal... I'm so clumsy! Thanks again for your quick answer! – MlleStrife Apr 05 '16 at 14:13