user3044672
user3044672

Reputation: 65

Value was either too large or too small for an Int32 in asp.net

I have a singup forum, in which there is aphone number field

code is:

try
{
    cz.SignUp(nametxt.Value, passtxt.Value,  
    Convert.ToInt32(DropDownList1.SelectedValue),  
    Convert.ToInt32(DropDownList2.SelectedValue),
    Convert.ToInt32(DropDownList3.SelectedValue),
    mailtxt.Value,Convert.ToInt32(numbtxt.Value));
    //GridView1.DataSource=ca.viewadmin();
    Lbe6.Text = ("Signup Success");             
}
catch
{
    lbe5.Text = ("FAILED");
}

But when I click on submit the button it shows me an error. Value was either too large or too small for an Int32.

I also tried uint and int64 but it did not work

Upvotes: 4

Views: 21137

Answers (2)

Rahul Tripathi
Rahul Tripathi

Reputation: 172568

Phone numbers are not NUMBERS

It is better to take string for storing the Phone Numbers.

On a side note:-

From MSDN:

Integer variables are stored as signed 32-bit (4-byte) integers ranging in value from -2,147,483,648 through 2,147,483,647.

And INT32

Int32 is an immutable value type that represents signed integers with values that range from negative 2,147,483,648 (which is represented by the Int32.MinValue constant) through positive 2,147,483,647 (which is represented by the Int32.MaxValue constant. The .NET Framework also includes an unsigned 32-bit integer value type, UInt32, which represents values that range from 0 to 4,294,967,295.

Upvotes: 2

SLaks
SLaks

Reputation: 887837

Phone numbers are not numbers.

You should use a string.

Remember: If you can't add it, it isn't a number.

Upvotes: 11

Related Questions