Wednesday, March 21, 2012

Hi I would like to import 1,000.00 price in DB - type??

Hi I would like to import into DB prices in format 1,000.00

I am using type money (mssql2004) but it doesnt let mi import this format.

Any ides. thx rek

Try DECIMAL(10,2)|||

Hi thank you for answer but it -

Error converting data type nvarchar to numeric.

Description:Anunhandled exception occurred during the execution of the current webrequest. Please review the stack trace for more information about theerror and where it originated in the code.

Exception Details:System.Data.SqlClient.SqlException: Error converting data type nvarchar to numeric.

Source Error:

An unhandled exception was generated during the execution of thecurrent web request. Information regarding the origin and location ofthe exception can be identified using the exception stack trace below.

|||

You'll need to convert the value first:

my_decimal_value = Decimal.Parse(my_nvarchar_value);

|||

thats sucks : I am using

<asp:SqlDataSource ID="SqlDataSource1" runat="server"

UpdateCommand="Update HSRSeason SET Price=@.Price > </asp:SqlDataSource>

Do I have to then work it through aspx.cs?

 

|||

Use this instead:

<asp:SqlDataSource ID="SqlDataSource1" runat="server"

UpdateCommand="Update HSRSeason SET Price=CONVERT(DECIMAL(10,2), @.Price)"> </asp:SqlDataSource>

|||

UpdateCommand="Update HSRSeason SET
Price=CONVERT(DECIMAL(10,2), @.Price)

And same error (it works without ",")

Error converting data type nvarchar to numeric.

Description:Anunhandled exception occurred during the execution of the current webrequest. Please review the stack trace for more information about theerror and where it originated in the code.

Exception Details:System.Data.SqlClient.SqlException: Error converting data type nvarchar to numeric.

Source Error:

An unhandled exception was generated during the execution of thecurrent web request. Information regarding the origin and location ofthe exception can be identified using the exception stack trace below.


Stack Trace:

[SqlException (0x80131904): Error converting data type nvarchar to numeric.]

|||

I'll bet you have the literal commas in the numbers. Use this instead:

UpdateCommand="Update HSRSeason SET
Price=CONVERT(DECIMAL(10,2), REPLACE(@.Price, ',', ''))

to replace the commas with a zero-length string before parsing.

Hope this helps...

|||

you were right. I am sorry I didnt tell you. Because I will make a person to write it with commas so it will be more secure to input prices.

What do you think about this idea? I will valide it so it will have to have a 00,000.00 format. But not there yet :-)

|||

The REPLACE function above will work regardless of whether there are commas in the string. If they are there, they will be removed, and if not the string will be passed as is.

Let me know if that works.

|||

the replace function (both) works fine as you suggested -

CONVERT(DECIMAL(10,2), REPLACE(@.Price, ',', ''))

I didnt know I can write functions in aspx. What kind of coding is this? It suprised me!

|||The REPLACE() function is actually an SQL function. I'm not sure if it's specific to T-SQL or if it is ANSI standard, but it's a very handy tool.|||lovely thx-for helpingsql

No comments:

Post a Comment