I have 4 textBox, I make a query to my BD and depending on what is selected in a DropDownList I must execute a multiplication either Txt1 * Txt3
or Txt2 * Txt3
and show me the result in Txt4
.
The method is the same for all txtBox:
protected void TxtImporte_TextChanged(object sender, EventArgs e)
{
OdbcConnection cd = new OdbcConnection("xxxxx");
cd.Open();
DataTable dtc = new DataTable();
OdbcCommand cmd = new OdbcCommand("SELECT T0.ItemName FROM OITM T0 WHERE T0.TreeType = 'T' and T0.ItmsGrpCod in (110,119) and T0.ItemName Like'%?' group by T0.ItemName", cd);
cmd.Parameters.AddWithValue("codigo", DropDownList1.SelectedItem.ToString());
OdbcDataAdapter da = new OdbcDataAdapter(cmd);
da.Fill(dtc);
if (dtc.Rows.Count == 1)
{
Double sueldo = 0;
Double.TryParse(TxtPiezas.Text, out sueldo);
Double remuneracion = 0;
Double.TryParse(TxtPrecio.Text, out remuneracion);
TxtImporte.Text = (sueldo * remuneracion).ToString("N2");
}
else
{
Double kilos = 0;
Double.TryParse(TxtKilos.Text, out kilos);
Double remuneracion = 0;
Double.TryParse(TxtPrecio.Text, out remuneracion);
TxtImporte.Text = (kilos * remuneracion).ToString("N2");
}
}
But when I run the page, it only executes the instruction after else for all the elements of the DropDownList. My query is well formulated because if I run from sql server it tells me if the product belongs to the range (110,119) or if it does not exist.
In SQL server:
SELECT T0.ItemName FROM OITM T0 WHERE T0.TreeType = 'T' and T0.ItmsGrpCod in (110,119)
Some values are always repeated.