I'm running a system on VB.net where I have a datagridview (MultiSelect) with the company's sales record. In another datagridview I show the articles of the selected sale (s) in the first DGV
"Select IdVenta, CodigoArticulo, Descripcion, Precio, Cantidad from Articulo_Venta WHERE " & ventas & " ORDER BY CodigoArticulo ASC"
The variable Sales is a chain of OR concatenations (eg SalesID = 3 OR SalesID = 2 OR SalesID = 6) from the following code:
Dim ventas As String = String.Empty
Dim contador As Integer = 1
For Each row As DataGridViewRow In IdVenta
If contador = IdVenta.Count Then
ventas = ventas & "IdVenta = " & row.Cells("IdVenta").Value
Else
ventas = ventas & "IdVenta = " & row.Cells("IdVenta").Value & " OR "
contador += 1
End If
Next
Everything works perfectly but in the resulting query, CodeArticle is repeated and it shows me the same article several times (Sold at different times or by different vendors), that is:
CodeArticle 1 | ... | Quantity = 3
CodeArticle 4 | ... | Quantity = 2
CodeArticle 1 | ... | Quantity = 6
and I need that when there is more than one CodeArticulo repeated I show it only once but with its summed amounts
CodeArticle 1 | ... | Quantity = 9