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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem reading numbers in an Excel file

Status
Not open for further replies.

jonbatts

Programmer
Apr 12, 2005
114
US
I'm using System.Data.Odbc to open an Excel file ([tt]excelConn = New OdbcConnection("Driver={Microsoft Excel Driver (*.xls)};DriverId=790;Dbq=" & sFileName & ";DefaultDir=" & sDirectory & ";")[/tt]) and am having no trouble opening the file, and reading each row via an OdbcDataReader, but for some reason, numbers are coming back as dbnulls. When I edit my Excel file by placing a "'" in front of a number (making it a string), it's read by the reader as a string, but left as a decimal number, it's dbnull. Any thoughts or ideas? Thanks.

 
I remember having the same problem where a column just contained numbers and the column type was set as a Number. I was accessing the data via a named range but the number column simply didn't bring any values back. I didnt have time to look into why it was happening so I just set the column type to Text and it worked fine.


____________________________________________________________
Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]

Need help finding an answer? Try the Search Facility or read FAQ222-2244.
 
Skip; earlier rows do contain text in the cells in question, but the rows with the cells that aren't coming back are only numbers.
 
ca8msm; I don't want the user to have to modify this file in any way before they upload it. (They download this file from another app and then import it into ours.) Any thoughts on how to do this without having to edit the Excel file? Thanks.
 
I don't want the user to have to modify this file
If you don't find the solution to the problem (time constraints meant I never did) a workaround may be to edit the file in code using the excel interop library. Ideally, this will be a last resort though and you'll figure out why it is happening in the first place.


____________________________________________________________
Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]

Need help finding an answer? Try the Search Facility or read FAQ222-2244.
 




Columns with both TEXT and NUMBERS are not handled well. Numbers are returned as NULL values.

You MUST fix the source.

Skip,

[glasses] [red][/red]
[tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top