problem with float numbers
#1

hello, i am updating db but it doesnt update correctly.

 

i have a datagridview where i get values from db.

 

2

 

when i try to update it to db, in db only appears the int part of the number in the col Probability.

 

i use this record to update:

 

 

record = "INSERT INTO t_moonstone_reward (a_type, a_index, a_giftindex, a_giftcount, a_giftprob, a_giftflag) VALUES ( 2545, " + dataGridView1[0, i].Value + ", " + dataGridView1[1, i].Value + ", " + dataGridView1[2, i].Value + ", " + dataGridView1[3, i].Value + ", " + dataGridView1[4, i].Value + " ) ON DUPLICATE KEY UPDATE a_index = " + dataGridView1[0, i].Value + ", a_giftindex = " + dataGridView1[1, i].Value + ", a_giftcount = " + dataGridView1[2, i].Value + ", a_giftprob = " + Convert.ToDecimal(dataGridView1[3, i].Value) + ", a_giftflag = " + dataGridView1[4, i].Value + " ;";

 

and when i run this sentence, update well but field a_giftprob updates bad because it only updates int part of the number (in this case number is 0,5 and only appears 0).

 

could anyone help me?

 

thanks in advance.

#2


Convert.ToDecimal(dataGridView1[3, i].Value)
You can simply usa  dataGridView1[3, i].Value.ToString(), since its in that format(be sure it contains. and not ,), check the table if the column is FLOAT or DOUBLE.

 
#3


Convert.ToDecimal(dataGridView1[3, i].Value)
You can simply usa  dataGridView1[3, i].Value.ToString(), since its in that format(be sure it contains. and not ,), check the table if the column is FLOAT or DOUBLE.

  

 

table column is float and my value contains ,

 

do i need to use that sentence or i need another?

#4

you also can use the "Replace" function

 

 

dataGridView1[3, i].Value.ToString().Replace( ",", "." );

#5


 

you also can use the "Replace" function

dataGridView1[3, i].Value.ToString().Replace( ",", "." );

 

yes, but in db also appear , and if i try to put . i cant

#6

Fixed with this:

 

 

you also can use the "Replace" function

dataGridView1[3, i].Value.ToString().Replace( ",", "." );

 

in db appears , but if i write . also works and in db appears like , so its ok.

 

thanks all.



Forum Jump:


Users browsing this thread: 1 Guest(s)