I'm trying to save the unique value resulting from a query into a double variable, since the same is stored in the database as double, so I can later be able to multiply it with a counter, with the following code:
public partial class CoronaClaraCant : Form
{
private int conteoCliks = 0;
private string producto = "CoronaClara";
private double precio;
public CoronaClaraCant()
{
InitializeComponent();
}
private void CoronaClara_Click(object sender, EventArgs e)
{
MySqlConnection conn = new MySqlConnection("server=localhost;database=database;username=root;password=***");
conn.Open();
string select = "SELECT precio FROM productos where prodnom = '" + producto + "';";
MySqlCommand cmd = new MySqlCommand(select, conn);
double result = cmd.ExecuteNonQuery();
conteoCliks++;
precio = result;
double total = (precio * conteoCliks);
lblcantidad.Text = conteoCliks.ToString();
lblprecio.Text = precio.ToString();
lbltotal.Text = total.ToString();
}
}
So far I've only been getting negative values:
I'm guessing this could be because the ExecuteNonQuery, but I haven't been able to assign a double value to a ExecuteScalar method, and I'm not sure if there are other parameters I should consider when saving a double value into a variable.