Unless you're passing basic constant literals (ie. the number 0 and 1 for a column, every time), then you should be using parameterized queries.
To do that, you need to specify in your SQL statement that "here I don't write the value, but I will provide the value of this parameter alongside the SQL statement".
Here's how to do that in .NET:
using (SqlCommand cmd = conn.CreateCommand())
{
cmd.CommandText = "INSERT INTO tablename (column) VALUES (@value)";
cmd.Parameters.Add("@value", 42.2); ^
cmd.ExecuteNonQuery(); ^ |
} | |
+-- these have to match up ----------+
Here you can see that I don't do any formatting of the value at all, I'm providing it as a normal C# literal value. I can of course also add it from a variable, again without having to reformat it to text.
You should be passing values this way, or you have to deal with all kinds of formatting issues, and if you're taking values from the user, you can also be setting yourself up for an SQL injection attack, which is bad!