473,598 Members | 3,389 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Input string was not in a correct format

Jim
im using asp.net, C# to enter data into a table in sql
server...howeve r im getting this error:

Input string was not in a correct format.
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.FormatEx ception: Input string was not in a
correct format.

Source Error:
Line 120:cmd.Paramet ers.Add("@commi ssion",SqlDbTyp e.Money);
Line 121:cmd.Paramet ers["@commissio n"].Direction=Para meterDirection. Input;
Line 122:cmd.Paramet ers["@commissio n"].Value =
Convert.ToDoubl e(txtinvoice.Te xt);
Line 123:cmd.Paramet ers.Add("@price sold",SqlDbType .Money);
Line 124:cmd.Paramet ers["@pricesold "].Direction=Para meterDirection

Similar error messages appear when I leave text fields blank that are
going to be inserted into fields in the table of datatype money,
datetime or int...

however when i execute this in query analyzer it works and inputs null
values for those fields:

declare @empid varchar(20), @inventoryid int, @clientid int,
@commission money,@pricesol d money, @datesold datetime, @invoiceid
int, @shippingcost money, @terms varchar(50), @details varchar(50),
@clienttype smallint, @checker int, @errordesc varchar(100)
set @empid = 'admin'
set @inventoryid = 14
set @clientid= 2
set @clienttype = 0
set @commission = null
exec STP_updateconsi gnment @empid, @inventoryid, @clientid,
@commission,@pr icesold, @datesold, @invoiceid, @shippingcost, @terms,
@details, @clienttype, @checker output, @errordesc output

If Im in enterprise manager and try to enter a blank value into one of
those fields I get: The value you entered is not consistent with the
data type or length of the column...so im wondering if the C# page is
sending my stored procedure a blank value instead of a Null and
causing this error?

any advice would be nice..thanks

-Jim
Jul 20 '05 #1
2 21086

"Jim" <ji********@mot orola.com> wrote in message
news:72******** *************** ***@posting.goo gle.com...
im using asp.net, C# to enter data into a table in sql
server...howeve r im getting this error:

Input string was not in a correct format.
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.FormatEx ception: Input string was not in a
correct format.

Source Error:
Line 120:cmd.Paramet ers.Add("@commi ssion",SqlDbTyp e.Money);
Line 121:cmd.Paramet ers["@commissio n"].Direction=Para meterDirection. Input;
Line 122:cmd.Paramet ers["@commissio n"].Value =
Convert.ToDoubl e(txtinvoice.Te xt);
Line 123:cmd.Paramet ers.Add("@price sold",SqlDbType .Money);
Line 124:cmd.Paramet ers["@pricesold "].Direction=Para meterDirection

Similar error messages appear when I leave text fields blank that are
going to be inserted into fields in the table of datatype money,
datetime or int...

however when i execute this in query analyzer it works and inputs null
values for those fields:

declare @empid varchar(20), @inventoryid int, @clientid int,
@commission money,@pricesol d money, @datesold datetime, @invoiceid
int, @shippingcost money, @terms varchar(50), @details varchar(50),
@clienttype smallint, @checker int, @errordesc varchar(100)
set @empid = 'admin'
set @inventoryid = 14
set @clientid= 2
set @clienttype = 0
set @commission = null
exec STP_updateconsi gnment @empid, @inventoryid, @clientid,
@commission,@pr icesold, @datesold, @invoiceid, @shippingcost, @terms,
@details, @clienttype, @checker output, @errordesc output

If Im in enterprise manager and try to enter a blank value into one of
those fields I get: The value you entered is not consistent with the
data type or length of the column...so im wondering if the C# page is
sending my stored procedure a blank value instead of a Null and
causing this error?

any advice would be nice..thanks

-Jim


As a complete guess, you're trying to convert a string value (possibly an
empty string, as you suspect) to a non-character data type, and the value
cannot be converted. Although an empty string can be converted to money, at
least. But without more information about the parameter values (ie. what is
the value of txtinvoice.Text when you run your C# code?), and the CREATE
TABLE statement for the table, it's not easy to give a good answer.

Simon
Jul 20 '05 #2
Jim (ji********@mot orola.com) writes:
im using asp.net, C# to enter data into a table in sql
server...howeve r im getting this error:

Input string was not in a correct format.
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.FormatEx ception: Input string was not in a
correct format.
...
however when i execute this in query analyzer it works and inputs null
values for those fields:
...
If Im in enterprise manager and try to enter a blank value into one of
those fields I get: The value you entered is not consistent with the
data type or length of the column...so im wondering if the C# page is
sending my stored procedure a blank value instead of a Null and
causing this error?


That error looks very much to me like something which is happnening
in the CLR, and thus before the data reaches SQL Server at all.

Judging from your code snippet, you will have to investigate in what
Convert.ToDoubl e accepts.

By the way, I am not really sure that converting to double is the
best thing to do. Double is an imprecise data type, and money is
exact. I don't know how the CLR handles these conversions, but
there could be a risk that the value entered in the text box is
not what ends up in the database, if you use all four decimals of
the money value.
--
Erland Sommarskog, SQL Server MVP, es****@sommarsk og.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
768
by: lianfe_ravago | last post by:
Input string was not in a correct format. 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.FormatException: Input string was not in a correct format. Source Error: Line 457: <tr>
5
2505
by: blackg | last post by:
Input string not in correct format -------------------------------------------------------------------------------- I am trying to view a picture from a table. I am getting this error Input string not in the correct format. Input string was not in a correct format. 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...
1
1839
by: amitbadgi | last post by:
Welcome back amitbadgi | Logout | Faq Knowledge Discovery Keys COMPUTER PROGRAMMING, DATA MINING, STATISTICS, ARTIFICIAL INTELLIGENCE * Settings * Photos * Lists * MVPs * Forums * Blogs
1
2842
by: amitbadgi | last post by:
I am gettign this error, while migration an app to asp.net Exception Details: System.FormatException: Input string was not in a correct format. Source Error: Line 19: Dim enddate = request.QueryString("enddate") Line 20: Line 21: if cint(eventid) = "0" then
0
2538
by: hudhuhandhu | last post by:
have got an error which says Input string was not in a correct format. as follows.. 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.FormatException: Input string was not in a correct format. Source Error: Line 237: Dim validNow As Integer = 1 Line...
0
11962
by: Anonieko | last post by:
Are there any javascript codes there? Answer: Yes On the PageLoad event call InitialClientControsl as follows /// <summary> /// This will add client-side event handlers for most of the form controls so
0
3160
by: sehguh | last post by:
Hiya Folks, I am Currently using windows xp. Also using Visual Web Developer 2005 and Microsoft Sql server 2005. The main page consists of an aspx page and a master page. The page also consists of a label control(hidden when run in browser). Also an Sql data source control connected to database tables for a photo album. Also label web control ID=UserIdValue. Also a Details View control ID=dvPictureInsert Problem is how to work out...
1
4517
by: sehguh | last post by:
Hello folks I have recently been studying a book called "sams teach yourself asp.net 2.0 in24 hours by scott mitchell. I have reached page 614 but when i tried to run an asp page called Photoadmin/default.aspx i got the following message and info. Input string was not in a correct format. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information...
1
4747
by: differentsri | last post by:
THIS IS AN ASP.NET 1.1 APPLICATION IAM TRYING TO UPDATE THE FIELD BUT I AM NOT ABLE TO UPDATE IT? CAN U TELL THE REASON ? IT IS GIVING THE FOLLOWING ERROR BELOW I HAVE ALSO GIVEN THE CODE OF THE PROGRAM PLEASE HELP ME Server Error in '/WebApplication1' Application. -------------------------------------------------------------------------------- Input string was not in a correct format. Description: An unhandled exception occurred...
0
7991
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7902
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8398
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8050
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
5850
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5438
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3898
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2412
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1250
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.