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
Solved

Parse Form.Text for SqlDbType,Money

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

808 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