Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 624
  • Last Modified:

Parse Form.Text for SqlDbType,Money

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
champ_010
Asked:
champ_010
  • 2
1 Solution
 
Timbo87Commented:
You also need to convert frmPrice.Text to a Decimal.

cmd.Parameters["@frmProductPrice"].Value=Decimal.Parse(frmPrice.Text);
0
 
champ_010Author Commented:
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
 
champ_010Author Commented:
I had to change my StoredProcedure to @frmProductPrice decimal(10,6). Works.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now