将2个网格视图的列相乘并以新的形式显示结果

时间:2017-01-12 23:56:54

标签: c# mysql

我需要乘以列valorprod * cantidad并显示一个名为小计的新列

enter image description here

代码在这里

 DataTable dsDetalle = new DataTable("Data");
 using (MySqlCommand commandSql = cn.CreateCommand())
 {
      commandSql.CommandType = CommandType.Text;
      commandSql.CommandText = "select * from detalle where idVenta=@idVenta and idlocal=@idlocal";
      commandSql.Parameters.AddWithValue("@idVenta", txt_boleta.Text);
      commandSql.Parameters.AddWithValue("@idlocal", txtlocal.Text);
      MySqlDataAdapter sqlAdapter = new MySqlDataAdapter(commandSql);
      sqlAdapter.Fill(dsDetalle);
 }

1 个答案:

答案 0 :(得分:1)

您可以动态创建计算列。

commandSql.CommandText = @"
   SELECT  *, ( valorprod * cantidad ) AS subtotal
   FROM    detalle
   WHERE   idVenta = @idVenta AND idlocal = @idlocal";