so far i've managed the code to load the results to gridview. Can anyone help me by grouping the products by productname and qty sold for each product. my goal is to see top 100 products and the qty's sold within 2 dates. here is my current code:
Code:Try Cursor = Cursors.WaitCursor Timer1.Enabled = True con = New SqlConnection(cs) con.Open() cmd = New SqlCommand("Select RTRIM(InvoiceNo),InvoiceDate,RTRIM(ProductName),RTRIM(Invoice_Product.Barcode),Invoice_Product.Qty,Invoice_Product.SalesRate,Invoice_Product.PurchaseRate, Invoice_Product.DiscountPer, Invoice_Product.Discount, Invoice_Product.VATPer, Invoice_Product.VAT, Invoice_Product.TotalAmount,Invoice_Product.Margin,Temp_stock_Company.Qty from InvoiceInfo,Invoice_Product,Product,Temp_Stock_Company where InvoiceInfo.Inv_ID=Invoice_product.InvoiceID and product.PID=Invoice_Product.ProductID and Product.PID=temp_Stock_Company.ProductID and InvoiceDate >=@d1 and InvoiceDate < @d2 Order by InvoiceDate", con) cmd.Parameters.Add("@d1", SqlDbType.DateTime, 30, "Date").Value = dtpDateFrom.Value.Date cmd.Parameters.Add("@d2", SqlDbType.DateTime, 30, "Date").Value = dtpDateTo.Value.Date.AddDays(1) cmd.CommandTimeout = 0 rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection) dgw.Rows.Clear() While (rdr.Read() = True) dgw.Rows.Add(rdr(0), rdr(1), rdr(2), rdr(3), rdr(4), rdr(5), rdr(6), rdr(7), rdr(8), rdr(9), rdr(10), rdr(11), rdr(12), rdr(13)) End While con.Close() Catch ex As Exception MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error) End Try




Reply With Quote
