Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations dencom on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel column name problem

Status
Not open for further replies.

dpdg

Programmer
May 23, 2005
148
US
I am debugging a module that gets data from an Excel spreadsheet and does some updating to rows in the database.

The problem is that there is a column that is called "Ref. Doc. Number" and I get an error because of the dots in the field name. I don't want to have to make the client take them out each time they have to do an update with the spreadsheet.
Code:
RefDocNumber = ds.Tables(0).Rows(i).Item("Ref. Doc. Number") <== this gives me an error.
I've tried using brackets: "[Ref. Doc. Number]" and I get the error that the field does not exist. Is there any way to get .NET to recognize that the " Ref. Doc. Number" string is actually a field name without taking out the dots?
 
Here's a thought:

Why not use the column index on your Dataset instead of the column name?

Just a thought.

HTH

Ron Repp

If gray hair is a sign of wisdom, then I'm a genius.
 
Why not use the column index on your Dataset instead of the column name?

> Yes, this solves the problem, but if the developer changes the order of the requested columns, or simply if he selects more (and insert before that column), the index will have to be changed. For me, it is a headache.
 
I've not tried this here, but it sometimes works in situations where using the string literal doesn't (though I don't know why!!):

[tt]
Dim badcolname as string = "Ref. Doc. Number"
RefDocNumber = ds.Tables(0).Rows(i).Item(badcolname)
[/tt]

Hope this helps.

[vampire][bat]
 
That's interesting. I never would have imagined that this would work.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top