I have an Excel spreadsheet with, among onther things, numbers that are identifiers.
My odbc reader should return me something like ‘55201562000016’, but too often it returns me something like ‘5.52016e+008’.
I only do the following, but apparently it does not suffice to tell the reader that it should be treated as a string and not an exponential integer :
siren = rdrxls("entr_siren").ToString().Trim()
siret = rdrxls("entr_siret").ToString().Trim()
I have tried this :
siren = Convert.ToInt64(rdrxls("entr_siren")).ToString().Trim()
siret = Convert.ToInt64(rdrxls("entr_siret")).ToString().Trim()
It should work, but sometimes it throws exceptions, because sometimes the data is erroneous (with letters for example) ; but I still need to fetch it.
Any idea ?
Thanks
You could use
Int64.TryParse()to see if you can cast the result into an Int64.TryParse()returns a boolean, indicating whether the cast was successfull or not.If it failed, keep the value as is, if it was successfull, overwrite the previously stored value with the ToString() of the cast result.
Hope this helps.