Cast to long

  • Thread starter Thread starter RP
  • Start date Start date
R

RP

I am using C# 2005 with Access XP.

I have a column with a LONG INTEGER data type. I have a class which
has a property:
---------------------------------------------------
Public long BPLNo
{
Get
{
return _BPLNo;
}

Set
{
_BPLNo = value;
}
}
--------------------------------------------------

While assigning value to this property, I am using following code, but
it is generating error of cast:

Class.BPLNo = Int64 (txtBPLNo.Text.ToString());
 
RP said:
While assigning value to this property, I am using following code, but
it is generating error of cast:

Class.BPLNo = Int64 (txtBPLNo.Text.ToString());

Try it like this:

Class.BPLNo = Convert.ToInt64(txtBPLNo.Text);

Or better still:

Int64 result;
bool success = Int64.TryParse(txtBPLNo.Text, out result);
if (success)
Class.BPLNo = result;
else
//The value typed in txtBPLNo is not recognized as an Int64 value.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top