0

I have a database table with all columns to allow nulls for testing purposes. Between all of my columns I have int, varchar or bit datatypes. When I try to submit the form I get the following error message:

Value was either too large or too small for an Int32.

Here is the code:

using (storeDataContext db = new storeDataContext())
        {

            db.Dealerssses.InsertOnSubmit(new Dealersss
            {  
                AppFName = txtFName.Text,
                AppLName = txtLName.Text,
                AppTitle = ddlTitles.SelectedItem.Text,
                AppPhone = Convert.ToInt32(txtPhone.Text),
                AppEmail = txtEmail.Text,
                AppAddress = txtAddress.Text,
                AppCity = txtCity.Text,
                AppState = txtState.Text,
                AppZip = Convert.ToInt32(txtZip.Text),
                BusName = txtBusName.Text,
                BusCA = Convert.ToInt32(txtBusResale.Text),
                BusContact = txtBusContact.Text,
                BusDBA = txtDBA.Text,
                BusEIN = Convert.ToInt32(txtBusEIN.Text),
                BusEmail = txtBusEmail.Text,
                BusFax = Convert.ToInt32(txtBusFax.Text),
                BusMonth = ddlMonthStart.SelectedItem.Text,
                BusNumEmployees = Convert.ToInt32(txtBusEmployees.Text),
                BusPhone = Convert.ToInt32(txtBusPhone.Text),
                BusYear = int.Parse(txtYearStart.Text),
                Active = false
            });
            db.SubmitChanges();
        };
2
  • @slaks, the values being posted in the form are between 1 and 15 digits, therefore it is impossible for the value to be too large for an int32. Commented Jan 21, 2011 at 3:37
  • 2
    Your code will mess up the valid zip code 07055. Do not store non-numeric data in integer columns! Commented Jan 21, 2011 at 3:40

3 Answers 3

2

Int32.MaxValue is 2,147,483,647, which is only 10 digits long.
Your values are too large for an Int32.

Your Phone, Fax, ZIP, and EIN fields should be strings (NVARCHARs), not numbers.

Sign up to request clarification or add additional context in comments.

Comments

1

I'm betting it's the value for your phone number fields. Int32 is a 4 byte integer with a max value of 2147483647. Most phone numbers will overflow that.

Comments

1

My guess is it is on your phone #'s Int32's have a value of:

-2,147,483,648 to 2,147,483,647

So if you have the phone # of 517111111 (5,171,111,111), you are too large.

You should use varchar/char for phone numbers.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.