Link to home
Start Free TrialLog in
Avatar of ANAT2403
ANAT2403Flag for Israel

asked on

Money in sql server 2000 with ASP.net 2.0

I have a table with a field of type money.
This field gets its currency according to the culture and I format
It in a formview to show the currency symbol:
<asp:TextBox ID="AmountTextBox" runat="server" Text='<%# Bind("Amount", "{0:C}") %>'></asp:TextBox>
When I update this field I get an error:
Input string was not in a correct format.
I update with the following command:

UPDATE Candidate SET Amount = CONVERT (money, @Amount)  WHERE (Candidate_id = @Candidate_id)

If I run the following script in sql query analyzer with a value of $300 it run and update OK. If I put it into a stored procedure and run it - its OK
If I run the store procedure with open in sql query analyzer it gives an error:
Invalid value..
What is the problem here?
Avatar of Anthony Perkins
Anthony Perkins
Flag of United States of America image

Don't rely on the regional settings of the Server and pass a numeric value (without any currency symbol) to the UPDATE statement.
can u check which value is giving error.. also send the exact error message..

Run profiler first, then run your application and find whether the values are passed correctly..

For example if your sp is like this

create spUpdate (@Amount money, @candidate_id int )...


and u call the ps like
exec spUpdate 300.00, 2  --- works well
exec spUpdate '3000.00',2  -- will give u the erro  
Avatar of ANAT2403

ASKER

comment to acperkins:
I don't want to pass the server the currency symbol but I have it becaule of he definition - "{0:C}"
How do I remove the currency symbol? Shall I do it in the event 'FormView1_ItemUpdated'  ?

comment to aneeshattingal:
I gave all the error messages:   INPUT STRING WAS NOT IN A CORRECT FORMAT
The problem is that I have a field which include a currency symbol and this make me problems in the update.
>>but I have it becaule of he definition - "{0:C}"<<
You don't have to.  You simply have not found out how.  {0:C}  is just formatting, try submitting without.  Or even better post in a more appropriate Topic Area such as:
https://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/ASP_DOT_NET/
I repeat my question:
How to remove the formatting or how to format without the currency symbol???
I found the solution to remove the currency symbol before the updating with the parsing command:
       Decimal tempdec = Decimal.Parse(temp22.Text, System.Globalization.NumberStyles.Currency);
I I had $300 I now have 300.
OK
Annie,

It is fine with me.

Anthony
Hi Annie,
It's fine with me too
ASKER CERTIFIED SOLUTION
Avatar of kodiakbear
kodiakbear

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial