Solved

Parse Form.Text for SqlDbType,Money

Posted on 2004-09-06
3
602 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
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.…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

735 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