System.Data.SqlClient.SqlException: Error converting data type numeric to decimal.

Hi There,

I'm using C# to get a value for a DOUBLE precision variable, called "Length", from a textBox using the following line:
Length = Convert.ToDouble( txtLength.Text )
I'm also using the following lines to prepare my stored procedure call:
arParms[9] = new SqlParameter("@Length", SqlDbType.Decimal, 5);
arParms[9].Value = record.Length;
My stored procedure has the following parameter definition:
@Length decimal(9,3)
My problem is that if someone types a value bigger than 999999 in the textbox he will get for sure the following error:
System.Data.SqlClient.SqlException: Error converting data type numeric to decimal.
I don't know how to either make sql or C# to truncate the value or catch the exception to automatically assign 0 to the parameter.
Please Help.
Moshe
0
moshe101
8/31/2004 5:38:56 PM
asp.net.sql-datasource 29906 articles. 0 followers. Follow

1 Replies
2012 Views

Similar Articles

[PageSpeed] 56

A rather basic approach would be...


try
{
Length = Convert.ToDouble(txt.Text)
}
catch
{
do something with the error
}
if Length > 99999
do something with the error
0
pkr
9/1/2004 12:39:05 PM
Reply:

Similar Artilces:

System.Data.SqlClient.SqlException: Error converting data type nvarchar to int.
I'm trying to implement encrypting/decrypting on a querystring (used this sample  http://www.devcity.net/Articles/47/1/encrypt_querystring.aspx)   .  However, now, my stored procedure doesn't work because it was expecting an integer, and now it's receiving the encrypted value and throws the error.  How do I tell my stored procedure to use a long encrypted value instead of the shorter integer it was expecting?    Do I cast it?  Do I convert it?  not sure what to do.. It used to be    UserID=123 Now it's somethi...

System.Data.SqlClient.SqlException: Error converting data type uniqueidentifier to nvarchar
I finally figure this out! Here is my blog: http://www.geekswithblogs.net/chrishan/archive/2005/07/16/47162.aspxIs there any other solution?http://www.bizsharp.com...

System.Data.SqlClient.SqlException: Error converting data type nvarchar to datetime.
I Receive this message when i add a Module to a page, What is wrong here? Are you using DNN 2.0? Are you using a core or 3rd party module (i.e. what module causes this error)? what are your globalization settings in the web.config? What are your current culture settings that you need to provide?Jeremy WhiteWebstone, LLCMy DNN Blog It's only happening when I include the module "EVENTS" into the portal. I donot use DNN 2.0 view post 479285Jeremy WhiteWebstone, LLCMy DNN Blog...

System.Data.SqlClient.SqlException: Syntax error converting the varchar value 'V' to a column of data type int
 I am using  a stored procedure which returns a value of charecter datatype 'V' to the calling program.I am getting an sql exception System.Data.SqlClient.SqlException: Syntax error converting the varchar value 'V' to a column of data type inti didnot define any int datatype in my tablethis is my codeSqlCommand com = new SqlCommand("StoredProcedure4", connection);com.CommandType = CommandType.StoredProcedure;  SqlParameter p1 = com.Parameters.Add("@uname", SqlDbType.NVarChar);SqlParameter p2 = com.Parameters.Add("@op...

Error:first chance exception of type 'System.Data.SqlClient.SqlException' occurred in system.data.dll
hi all, I have a stored procedure to insert reecords on multiple table and when use this in asp.cs, I got this error:-   first chance exception of type 'System.Data.SqlClient.SqlException' occurred in system.data.dll. Here is my sp             create procedure userRegistration ( @FirstName nvarchar(50), @LastName nvarchar(50), @EmailId varchar(100), @Password nvarchar(50), @CreationDate nvarchar(50), @EffectiveDate nvarchar(50), @AddressLine1 nvarchar(50), @City nvarchar(50), @State nvarchar(50),...

System.Data.SqlClient.SqlException: The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.
After testing out the application i write on the local pc. I deploy it to the webserver to test it out. I get this error. System.Data.SqlClient.SqlException: The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value. Notes: all pages that have this error either has a repeater or datagrid which load data when page loading. At first I thought the problem is with the date, but then I can see that some other pages that has datagrid ( that has a date field) work just fine. anyone having this problem before?? hopefully you guys can help...

System.Data.SqlClient.SqlException: The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value
After clicking my update button I'm receiving this error:    The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value. The statement has been terminated. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Data.SqlClient.SqlException: The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value. The statement has been...

SQL Server Error: "Arithmetic overflow error converting numeric to data type numeric"
I'm still quite new to SQL, and so I may be missing something quite obvious. Apologies in advance if that's the case. I've included my query at the bottom of the message as it is quite long; my problem is that I get "Arithmetic overflow error converting numeric to data type numeric" when the first parameter to my COALESCE calls is not NULL. That is, the COALESCEs and the query work as I expect when SUM(cust_vw_actual.Actual) is NULL (they return 0.00), but if it isn't I get the error. I am also getting "Warning: Null value eliminated from aggregate.&...

A first chance exception of type 'System.Data.SqlClient.SqlException' occurred in system.data.dll
Hi, I've written this code multiple times now. But for the first time i get an error at the line underlined. My procedure runs perfectly when i execute it through Sql Query analyzer. plzz help.. Its urgent and am unable to find the reason for this error "A first chance exception of type 'System.Data.SqlClient.SqlException' occurred in system.data.dll" Thanks !SqlConnection conn = new SqlConnection(DbConnectionString); conn.Open(); SqlCommand cmd = conn.CreateCommand(); cmd.CommandText = "dbo.rqryTradesPRR"; cmd.Parameters.Add("@COBDate"...

A first chance exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll
I'm trying to pull data from database using a stored procedure to return to an autocomplete extender. It all worked fine with one stored procedure but not with the second one, which has exactly the same SQL code behind it...Ok here is the code from my web service:    Public Function getAutocompleteTitles(ByVal prefixText As String, ByVal count As Integer) As String()        Dim titelAdapter As moviesetsTableAdapters.SelectMoviesetsByTitleTableAdapter = New moviesetsTableAdapters.SelectMoviesetsByTitleTableAdapter    &n...

The .Net Data SQL Provider (System.Data.SqlClient) requires Microsoft Data Access Components(MDAC) version 2.6 or later.
I am getting error like The .Net Data SQL Provider (System.Data.SqlClient) requires Microsoft Data Access Components(MDAC) version 2.6 or later. i am working with windowsXP. Already in my system i have MDAC 2.7. I donot know why am i getting error like this. anybody help me please...

Linq Error Cannot implicitly convert type 'System.Collections.Generic.IEnumerable<AnonymousType#1>' to 'System.Data.EnumerableRowCollection<System.Data.DataRow>'.
Hi I am using a AdventureWorks database and trying to use LINQ to query the data. i am not able to get the AsDataView() if i don't declare query as EnumerableRowCollection. But if i declare the query EnumerableRowCollection it shows me an error Cannot implicitly convert type 'System.Collections.Generic.IEnumerable' to 'System.Data.EnumerableRowCollection'. AdventureWorks.AdventureWorksDataContext db = new AdventureWorks.AdventureWorksDataContext(); EnumerableRowCollection query = from t in db.TransactionHistories.AsEnumerable() ...

System.Data.SqlClient VS. System.Data.Sql
What is the difference between .SqlClient and .Sql  When I am on the msdn site I notice that SqlCommand, SqlDataReader, etc.. are in the System.Data.Sql MENU, but, when I select the information for those related classes it says that they are members of the namespace: "System.Data.SqlClient"   thanks?   The System.Data.Sql namespace contains classes that support SQL Server-specific functionality and  System.Data.SqlClient namespace is the.NET Framework Data Provider for SQL Server. The.NET Framework Data Provider for SQL Server describes a collection of...

strange SQL error System.Data.SqlClient.SqlException
Hi there, i copied some insert code from one page to another and it keeps throwing me this error, i was wondering if anyone can help me out. Here is the error System.Data.SqlClient.SqlException: The name "Credit" is not permitted in this context. Valid expressions are constants, constant expressions, and (in some contexts) variables. Column names are not permitted. at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) at System.Data.Sql...

Web resources about - System.Data.SqlClient.SqlException: Error converting data type numeric to decimal. - asp.net.sql-datasource

Resources last updated: 2/4/2016 4:49:10 AM