Witam, tak jak w temacie mam problem z dodaniem wartości dziesiętnych do bazy. Połączenie i dodawanie wartości całkowitych działa, w bazie ustawione rekordy liczbowe na typ Float. Problem: gdy próbuje dodać do bazy np. fat = 2,1 to wyskakuje błąd "error converting data type varchar to float" . Jest jakiś sposób aby to zadziałało ?
Kod:
private void button1_Click(object sender, EventArgs e)
{
try
{
if (name.Text != "" & protein.Text != "" & carbs.Text != "" & fat.Text != "" & kcal.Text != "")
{
cn.Open();
cmd.CommandText = "INSERT INTO products (prod_name, protein, carbs, fat, kcal) values ( N'" + name.Text + "','" + Convert.ToDouble(protein.Text) + "','" + Convert.ToDouble(carbs.Text) + "','" + Convert.ToDouble(fat.Text) + "','" + Convert.ToDouble(kcal.Text) + "')";
cmd.ExecuteNonQuery();
cmd.Clone();
MessageBox.Show("Pomyślne dodanie produktu!", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
cn.Close();
name.Text = "";
protein.Text = "";
carbs.Text = "";
fat.Text = "";
kcal.Text = "";
loadlist();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
cn.Close();
}
}