Solved

Parse Form.Text for SqlDbType,Money

Posted on 2004-09-06
3
563 Views
Last Modified: 2012-08-13
Hi, I'm getting an error that I think is related to my SqlParameters. I'm not sure how to convert the values from formField.Text to the correct type for SqlDbType.  Here are the 2 that I think are causing problems:

cmd.Parameters.Add("@frmProductPrice",SqlDbType.Money);
cmd.Parameters["@frmProductPrice"].Value=frmPrice.Text;

//Do I need to indicate precision here?
cmd.Parameters.Add("@frmProductPrice",SqlDbType.Decimal);
cmd.Parameters["@frmProductPrice"].Value=Decimal.Parse(frmPrice.Text);


My error message:"System.FormatException: Input string was not in a correct format."
The error message refers to the line:

cmd.ExecuteNonQuery();
0
Comment
Question by:champ_010
  • 2
3 Comments
 
LVL 15

Accepted Solution

by:
Timbo87 earned 100 total points
ID: 11990997
You also need to convert frmPrice.Text to a Decimal.

cmd.Parameters["@frmProductPrice"].Value=Decimal.Parse(frmPrice.Text);
0
 
LVL 1

Author Comment

by:champ_010
ID: 11991761
Hi Thanks--I got the data in the database now but if I put 34.57 in--it will round it to 35.00.  Do I have to indicate precision in the decimal or do I have to put something in "formula" in the SqlServer for my money datatype field?
0
 
LVL 1

Author Comment

by:champ_010
ID: 11992019
I had to change my StoredProcedure to @frmProductPrice decimal(10,6). Works.
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now