Click here to Skip to main content
15,741,406 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Long variable= Convert.ToInt64(row["SHP_ID"])
When value comes from "33300109....... "

We are getting below exception.

Data: {System.Collections.ListDictionaryInternal}
    HResult: -2146233066
    HelpLink: null
    InnerException: null
    Message: "Value was either too large or too small for an Int64."
    Source: "mscorlib"
    StackTrace: "   at System.Number.ParseInt64(String value, NumberStyles options, NumberFormatInfo numfmt)\r\n   at System.Int64.Parse(String s)"
    TargetSite: {Int64 ParseInt64(System.String, System.Globalization.NumberStyles, System.Globalization.NumberFormatInfo)}

can anyone plz suggest

What I have tried:

I tried this, but still having same exception.

Updated 14-Apr-23 2:00am
TheRealSteveJudge 14-Apr-23 7:44am    
What is the exact value of the data you would like to convert to Int64?
monika rao 14-Apr-23 7:52am    
"33300109396272646795 "
Gerry Schmitz 16-Apr-23 12:03pm    
A "shipper id" is a nonsense number; probably made up of sub-fields. You're probably wanting an (sql) "entity / identity id" instead.

See Int64 Struct (System) | Microsoft Learn[^] for upper and lower limits. You could use a Decimal Struct (System) | Microsoft Learn[^] type, but it rather depends on what you are trying to do with this value.
Share this answer
The error message is indicating exactly what is wrong.

You are trying to convert a string "33300109396272646795" to an INT64 numeric value.

If you compare the value

to the maximum value for an INT64

you can see, that "33300109396272646795"
cannot be converted to INT64.
It is too big!

See Int64.MaxValue Field (System) | Microsoft Learn[^]

It might also be a good idea to read this documentation about C# numeric types:
Integral numeric types - C# reference | Microsoft Learn[^]

A solution would be to use a different conversion method "Convert.ToUInt64" as described here:
Convert.ToUInt64 Method (System) | Microsoft Learn[^]

UInt64 can hold values from 0 to 18,446,744,073,709,551,615
Share this answer

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

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