Question : Regional settings GREEK , decimal separator "," sql server 2000, But does not update a textbox tha binds to a float field,C# framework 2.0

I want a textbox whose text property is bind to a float field in sql server 2000.
The pc has regional settings GREEK and  the decimal point is comma ",".So I change the default language for user to GREEK in sql server 2000.I remark that the float values in sql  server database have comma separator.But when I set a float value in a textBox that binds to a float field , exception appears "Error converting data type nvarchar to float."The text property is bind to the float field.In the textBox I set for example "23,56".

..................................

 if (textBoxFPA.Text != "")
                        cmdInsertDoc.Parameters.AddWithValue("@FPA", textBoxFPA.Text);
                    else
                        cmdInsertDoc.Parameters.AddWithValue("@FPA", DBNull.Value);
            ........................................................  

                    cmdInsertDoc.CommandText = "Update  Documents set  ID_NUMBER = @ID_NUMBER," +
                                                                            "SUPPLIER_AFM = @Supplier_AFM," +
                                                                            "PRODUCT_TYPE = @Prod_type," +
                                                                            "PRODUCT = @Prod_ID," +
                                                                            "PRODUCT_DETAIL = @Prod_Details," +
                                                                            "DATETIME_version = @Date_Version," +
                                                                            "DATETIME_RECEIPT = @Date_Receipt," +
                                                                            "TOTAL_PRICE = @TotalPrice," +
                                                                            "PRICE_PER_QUANTITY = @PricePerQuantity," +
                                                                            "TYPE_QUANTITY = @TypeQuantity," +
                                                                            "PAYED = @IsPayed," +
                                                                            "MONEYPAYED = @MoneyPayed," +
                                                                            "MONEYREST = @MoneyRest," +
                                                                            "ORDER_ID = @OrderID," +
                                                                            "FPA = @FPA," + "Quantity=@Quantity" +
                                                                            string.Format(" where ID_NUMBER = {0}", (int)dataGridViewDocuments.CurrentRow.Cells[0].Value);
                    cmdInsertDoc.Connection = dOCUMENTSTableAdapter.Connection;
                    cmdInsertDoc.Connection.Open();
                    cmdInsertDoc.ExecuteNonQuery();

Answer : Regional settings GREEK , decimal separator "," sql server 2000, But does not update a textbox tha binds to a float field,C# framework 2.0

Oops, sorry - I missed that the SQL data type "float" is 8 bytes, which corresponds to C#'s "double" type, not "float".

You have found a correct answer.

cmdInsertDoc.Parameters.AddWithValue("@FPA", double.Parse(textBoxFPA.Text));

Though, you may consider checking first whether or not the text box contains a valid value for a double:

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
if (textBoxFPA.Text.Trim() != "")
{
    double fpa;
 
    if (!double.TryParse(textBoxFPA.Text, out fpa))
    {
        MessageBox.Show("textBoxFPA contains an invalid value.");
        return;
    }
 
    cmdInsertDoc.Parameters.Add(new SqlParameter("@FPA", System.Data.SqlDbType.Float, sizeof(double))).Value = fpa;
}
Random Solutions  
 
programming4us programming4us