Solved

Parse Form.Text for SqlDbType,Money

Posted on 2004-09-06
3
575 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

910 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

16 Experts available now in Live!

Get 1:1 Help Now