Type Casting to long

  • Thread starter Thread starter Lalit Bhatia
  • Start date Start date
L

Lalit Bhatia

When we retrieve data from a int field from a datatable and if I write
lValue = (long)dtTable.Rows[0]["Fld1"]
it generates an error at runtime. whereas it should be done because we are
converting int to long which should be possible.
but if I use Convert.ToInt64 it does give any error.

What is reason for that?

Regards,
Lalit Bhatia
 
What if you try :

lValue = (long)(int)dtTable.Rows[0]["Fld1"]

else post the error message and see if you can repro the problem for us with
simple code such as :
object o;

int intValue=10;

long longValue;

o=intValue;

//longValue=(long)o; fails

longValue=(long)(int)o; // works

MessageBox.Show(longValue.ToString());

longValue=Convert.ToInt64(o);

MessageBox.Show(longValue.ToString());




Patrice
 
Back
Top