Save in a variable and multiply double value query result C#/MySql -
i'm trying save unique value resulting query double variable, since same stored in database double, can later able multiply counter, 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 productos 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 been getting negative values:
i'm guessing because executenonquery, haven't been able assign double value executescalar method, , i'm not sure if there other parameters should consider when saving double value variable.
you want select
data database , calling executenonquery
used insert,update or delete commands.
you need call executereader
or if want data in datatable
can fill datatable
.
sqldatareader rdr = cmd.executereader(); if (rdr.hasrows) { if (rdr.read()) { precio = (double)rdr["precio"]; } }