So my question is, why am I kept getting the "Error: Value was either too large or too small for an Int32." error? What and where should I change the data type to make this work?
If it's numeric(18), why are you setting the parameter to Int32? It should be decimal, I believe.
Brian
"Trust in the Lord and do what is good; dwell in the land and live securely. Take delight in the Lord, and He will give you your heart's desires" (Psalm 37: 3-4).
I think this is an error while converting the textbox value to integer. What is the value in the textbox? Are you getting error for any value entered? Have you tried with values like 100 or some some number even if they may not represent valid input in the
textbox?
You are probably overflowing the Int32. It only goes up to 2,147,483,648. Unless the phone numbers start with a 1 area code you are probably going to overflow. What numbers are getting put into the textbox? You could use a long or and unsigned int
mychucky
Contributor
4358 Points
3709 Posts
Error: Value was either too large or too small for an Int32.
Aug 07, 2008 05:43 PM|LINK
I kept getting this error when trying to insert data into my SQL Server database.
The SQL Database table data type for this field phone field is numeric(18, 0)
The Store Procedure variable data type is numeric(18, 0)
And the code behind for inserting the phone number back into the database table looks like this:
sqlComm.Parameters.Add("@homePhone", SqlDbType.Int).Value = Convert.ToInt32(txtHphone.Text);So my question is, why am I kept getting the "Error: Value was either too large or too small for an Int32." error? What and where should I change the data type to make this work?
bmains
All-Star
29116 Points
5886 Posts
MVP
Re: Error: Value was either too large or too small for an Int32.
Aug 07, 2008 05:49 PM|LINK
Hey,
If it's numeric(18), why are you setting the parameter to Int32? It should be decimal, I believe.
"Trust in the Lord and do what is good; dwell in the land and live securely. Take delight in the Lord, and He will give you your heart's desires" (Psalm 37: 3-4).
sambeetpatra
Participant
1386 Points
227 Posts
Re: Error: Value was either too large or too small for an Int32.
Aug 07, 2008 05:50 PM|LINK
I think this is an error while converting the textbox value to integer. What is the value in the textbox? Are you getting error for any value entered? Have you tried with values like 100 or some some number even if they may not represent valid input in the textbox?
gibble
Participant
786 Points
226 Posts
Re: Error: Value was either too large or too small for an Int32.
Aug 07, 2008 05:56 PM|LINK
First, if it's a phone number store it as a string.
Second, an int32 only ranges from +/- 2,147,483,648 which is only 10 digits...and not even all of them.
huenemeca
Participant
835 Points
181 Posts
Re: Error: Value was either too large or too small for an Int32.
Aug 07, 2008 05:57 PM|LINK
http://www.BlogOfSeparation.com
mychucky
Contributor
4358 Points
3709 Posts
Re: Error: Value was either too large or too small for an Int32.
Aug 07, 2008 06:01 PM|LINK
I changed it into decimal and this is the error I got.
Error: Failed to convert parameter from a Decimal to a Int32.
mychucky
Contributor
4358 Points
3709 Posts
Re: Error: Value was either too large or too small for an Int32.
Aug 07, 2008 06:11 PM|LINK
The number input into the textbox have this formating:
9999999999
huenemeca
Participant
835 Points
181 Posts
Re: Error: Value was either too large or too small for an Int32.
Aug 07, 2008 06:14 PM|LINK
http://www.BlogOfSeparation.com
mychucky
Contributor
4358 Points
3709 Posts
Re: Error: Value was either too large or too small for an Int32.
Aug 07, 2008 06:21 PM|LINK
So the datatype in the database table should be set to varchar(10), correct?
huenemeca
Participant
835 Points
181 Posts
Re: Error: Value was either too large or too small for an Int32.
Aug 07, 2008 06:29 PM|LINK
Yes, as long as the number will never be larger than 10 characters
http://www.BlogOfSeparation.com