Last post Nov 21, 2010 02:48 PM by firstname.lastname@example.org
Nov 19, 2010 09:58 PM|minhpg|LINK
Hi all guys
My problem is that i have string "28538.38", when i convert.todecimal("28538.38") and insert into table, the value in
the table is 2853838, i want it is the same value 28538.38 (my field is decimal type).
How can i fix it?
thank in advanced.
Nov 19, 2010 10:49 PM|ashish.chotalia|LINK
You might have defined SQL datatype with Decimal(18,0).
You should change it to somet thing like Decimal(10,2) which will allow total of 10 character and to digit after decimal point.
Let me know if you have any queries.
Nov 19, 2010 11:59 PM|sandippatil44|LINK
i want it is the same value 28538.38 (my field is decimal type).
In case you still need to change the table's column type you can use T-SQL , the sintax for MS SQL is:
ALTER TABLE table ALTER COLUMN column_name new_data_type
ALTER TABLE MyTable ALTER COLUMN MyColumn decimal(16, 2)
try this or u can go to enterprise Manager and went to design view of the table and changed the data type of the field.
Nov 20, 2010 12:49 AM|minhpg|LINK
my string is Salerate="28538.38"
i have changed my field to decimal(10,2) the value in table is 28538.00, if i changed my field to money type the value in the table is 2853838.00
Nov 20, 2010 01:23 AM|ashish.chotalia|LINK
Try with Numeric(10,2) datatype. That should resolve your issue.
Nov 20, 2010 01:38 AM|minhpg|LINK
if i changed to Numeric(10,2), the same problem with money type, the value in the table is 2853838. (i hope it is 28538.38, the same with my string input).
Nov 20, 2010 02:23 AM|ashish.chotalia|LINK
Can you please post you code?
Nov 20, 2010 02:34 AMemail@example.com|LINK
please check your localization settings in your aspx page or in the web.config.
Nov 20, 2010 02:57 AM|minhpg|LINK
I defind function is called InsertExchangeRate in BLL to run sql store pro in database like this
int InsertExchangeRate(string title,
then in my app page i call this function
String SaleRate = "28538.38";
now i try to change my field to float and my variable to Double in order check it. but we still find solution for that problem.
Nov 20, 2010 03:18 AM|minhpg|LINK
if i change culture, the same problem occur. thanks
Nov 20, 2010 03:38 AM|ashish.chotalia|LINK
While passing this parameter to the code behind you might have put SqlParameter right? Can you please check datatype over there.
else just try to put debug point on this line
string str = "28538.38";
Decimal dc = Convert.ToDecimal(str);
This is working fine on my sample, there might be issue while you are passing to database.
Nov 20, 2010 12:01 PMfirstname.lastname@example.org|LINK
Nov 20, 2010 10:15 PM|minhpg|LINK
I try to debug, but the problem remain, the value in table is 2853838, my code are below:
string SaleRate = "28538.38";
Decimal dc = Convert.ToDecimal(SaleRate);
// ExchangeRate.InsertExchangeRate(Titleex[i], Convert.ToDecimal(Buyrateex[i]),Convert.ToDecimal(SaleRate));
// SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["LocalSqlServer"].ConnectionString);
String sqlstr = String.Format(@"insert into ibss_ExchangeRate(AddedDate,AddedBy,Title,BuyRate,SaleRate)values('2010/11/21','admin','USD',123456," + dc + ")");
using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["LocalSqlServer"].ConnectionString))
SqlCommand command = new SqlCommand(sqlstr, cn);
Nov 21, 2010 02:48 PMemail@example.com|LINK
ok try to change the string "28538.38" to "28538,38" (Comma instead of dot);
run your program again and see if the value gets correct.
Check if the decimal value is correct.
And if your store it in a database check if the database value gets correct.
If yes your problem is definitly a localization problem (Either client webserver or db-server related).