I am trying to pass a decimal value from C# to an SQL database. I build up an INSERT query string and send it along using a SqlCommand. The problem I'm having is that when I enter the values in my Windows Form they are saved with a comma separating the decimal point (i.e. 55,679). This is evident in the SQL query string (I've checked with debugging). But it seems as though the database query expects a decimal point (i.e. 55.679). It's probably got to do with my region and the standard there (i.e. Europe uses "," as the decimal separator). Anyone know how to set this?
The code for the function is below. The problems exist in the Vmax, Vmin, Imax.
public bool addBattery(Battery b)
{
bool outcome = false;
string sql = @"INSERT INTO [BATTERY_INFO]
(BatteryType, VoltageMax, VoltageMin, Capacity, CurrentMax, Manufacturer, Serial)
VALUES ('" + b.BatteryType.ToString() + "'," + b.Vmax + "," + b.Vmin + ","
+ b.Capacity + ","+b.Imax+ ",'"+b.Manufacturer.ToString()+"','"+b.Serial.ToString()+"')";
SqlCommand command = new SqlCommand(sql, this.sql_conn);
try
{
command.ExecuteNonQuery();
MessageBox.Show("Inserted Battery Successfully");
outcome = true;
}
catch (Exception e)
{
MessageBox.Show("SQL INSERT error \n\n" + e.Message);
}
return outcome;
}