Error: Value was either too large or too small for an Int32.http://forums.asp.net/t/1302337.aspx/1?Error+Value+was+either+too+large+or+too+small+for+an+Int32+Thu, 07 Aug 2008 19:15:02 -040013023372543966http://forums.asp.net/p/1302337/2543966.aspx/1?Error+Value+was+either+too+large+or+too+small+for+an+Int32+Error: Value was either too large or too small for an Int32. <p>&nbsp;I kept getting this error when trying to insert data into my SQL Server database.</p> <p>The SQL Database table data type for this field phone field is numeric(18, 0)</p> <p>The Store Procedure variable data type is numeric(18, 0)</p> <p>And the code behind for inserting the phone number back into the database table looks like this: <br> </p> <pre class="prettyprint">sqlComm.Parameters.Add(&quot;@homePhone&quot;, SqlDbType.Int).Value = Convert.ToInt32(txtHphone.Text);</pre>&nbsp;&nbsp; <p>So my question is, why am I kept getting the &quot;Error: Value was either too large or too small for an Int32.&quot; error? What and where should I change the data type to make this work?<br> </p> 2008-08-07T17:43:56-04:002543974http://forums.asp.net/p/1302337/2543974.aspx/1?Re+Error+Value+was+either+too+large+or+too+small+for+an+Int32+Re: Error: Value was either too large or too small for an Int32. <p>Hey,</p> <p>If it's numeric(18), why are you setting the parameter to Int32?&nbsp; It should be decimal, I believe.</p> 2008-08-07T17:49:51-04:002543976http://forums.asp.net/p/1302337/2543976.aspx/1?Re+Error+Value+was+either+too+large+or+too+small+for+an+Int32+Re: Error: Value was either too large or too small for an Int32. <p>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?</p> 2008-08-07T17:50:21-04:002543996http://forums.asp.net/p/1302337/2543996.aspx/1?Re+Error+Value+was+either+too+large+or+too+small+for+an+Int32+Re: Error: Value was either too large or too small for an Int32. <p>First, if it's a phone number store it as a string.</p> <p>Second, an int32 only ranges from &#43;/- 2,147,483,648 which is only 10 digits...and not even all of them.<br> </p> 2008-08-07T17:56:45-04:002543998http://forums.asp.net/p/1302337/2543998.aspx/1?Re+Error+Value+was+either+too+large+or+too+small+for+an+Int32+Re: Error: Value was either too large or too small for an Int32. You are probably overflowing the Int32.&nbsp; It only goes up to 2,147,483,648.&nbsp; Unless the phone numbers start with a 1 area code you are probably going to overflow.&nbsp; What numbers are getting put into the textbox?&nbsp; You could use a long or and unsigned int<br> 2008-08-07T17:57:27-04:002544013http://forums.asp.net/p/1302337/2544013.aspx/1?Re+Error+Value+was+either+too+large+or+too+small+for+an+Int32+Re: Error: Value was either too large or too small for an Int32. <p>&nbsp;</p> <p></p> <blockquote><span class="icon-blockquote"></span> <h4>bmains</h4> <p></p> <p>Hey,</p> <p>If it's numeric(18), why are you setting the parameter to Int32?&nbsp; It should be decimal, I believe.</p> <p></p> </blockquote> <p></p> <p>I changed it into decimal and this is the error I got.<br> <br> Error: Failed to convert parameter from a Decimal to a Int32. <br> </p> 2008-08-07T18:01:08-04:002544033http://forums.asp.net/p/1302337/2544033.aspx/1?Re+Error+Value+was+either+too+large+or+too+small+for+an+Int32+Re: Error: Value was either too large or too small for an Int32. <p>&nbsp;The number input into the textbox have this formating:</p> <p>9999999999</p> <p>&nbsp;<br> </p> 2008-08-07T18:11:01-04:002544041http://forums.asp.net/p/1302337/2544041.aspx/1?Re+Error+Value+was+either+too+large+or+too+small+for+an+Int32+Re: Error: Value was either too large or too small for an Int32. That number is way to big for an int32.&nbsp; You should just store it as a string.(varchar)<br> 2008-08-07T18:14:17-04:002544063http://forums.asp.net/p/1302337/2544063.aspx/1?Re+Error+Value+was+either+too+large+or+too+small+for+an+Int32+Re: Error: Value was either too large or too small for an Int32. <p>&nbsp;So the datatype in the database table should be set to varchar(10), correct?<br> </p> 2008-08-07T18:21:32-04:002544081http://forums.asp.net/p/1302337/2544081.aspx/1?Re+Error+Value+was+either+too+large+or+too+small+for+an+Int32+Re: Error: Value was either too large or too small for an Int32. <p>Yes, as long as the number will never be larger than 10 characters<br> </p> 2008-08-07T18:29:16-04:002544126http://forums.asp.net/p/1302337/2544126.aspx/1?Re+Error+Value+was+either+too+large+or+too+small+for+an+Int32+Re: Error: Value was either too large or too small for an Int32. <p>You may want to define a slightly larger size. something like varchar(20). In case the number needs to be stored with extension [or, even an international number] you will need to change it again in future.</p> 2008-08-07T18:56:39-04:002544159http://forums.asp.net/p/1302337/2544159.aspx/1?Re+Error+Value+was+either+too+large+or+too+small+for+an+Int32+Re: Error: Value was either too large or too small for an Int32. <p>&nbsp;Thanks for all your help. I got it working now.<br> </p> 2008-08-07T19:15:02-04:00