Hi everyone,
i'm populating datagridview from database, plus i add two more columns which are not stored in DB, those columns are calculated and then i add them to DataGridView.
But problem is that i have 4 records in DB, but in datagridview i get first record 4 times, instead each record one time.
Here is my code:
OrderID = Convert.ToInt32(dt1.Rows[0]["OrderID"].ToString()); OrderDate = Convert.ToDateTime(dt1.Rows[0]["OrderDate"]).ToString("dd.MM.yyyy"); Shipper = dt1.Rows[0]["Shipper"].ToString(); Consignee = dt1.Rows[0]["CName"].ToString(); Desc1 = dt1.Rows[0]["S1Description"].ToString(); Desc2 = dt1.Rows[0]["S2Description"].ToString(); Desc3 = dt1.Rows[0]["S3Description"].ToString(); Desc4 = dt1.Rows[0]["S4Description"].ToString(); Desc5 = dt1.Rows[0]["S5Description"].ToString(); Qty1 = Math.Round(Convert.ToDecimal(dt1.Rows[0]["S1Qty"]), 2); Qty2 = Math.Round(Convert.ToDecimal(dt1.Rows[0]["S2Qty"]), 2); Qty3 = Math.Round(Convert.ToDecimal(dt1.Rows[0]["S3Qty"]), 2); Qty4 = Math.Round(Convert.ToDecimal(dt1.Rows[0]["S4Qty"]), 2); Qty5 = Math.Round(Convert.ToDecimal(dt1.Rows[0]["S5Qty"]), 2); Up1 = Math.Round(Convert.ToDecimal(dt1.Rows[0]["S1Up"]), 2); Up2 = Math.Round(Convert.ToDecimal(dt1.Rows[0]["S2Up"]), 2); Up3 = Math.Round(Convert.ToDecimal(dt1.Rows[0]["S3Up"]), 2); Up4 = Math.Round(Convert.ToDecimal(dt1.Rows[0]["S4Up"]), 2); Up5 = Math.Round(Convert.ToDecimal(dt1.Rows[0]["S5Up"]), 2); VAT1 = Math.Round(Convert.ToDecimal((Convert.ToDecimal(dt1.Rows[0]["VAT1"]) + 100) / 100), 2); VAT2 = Math.Round(Convert.ToDecimal((Convert.ToDecimal(dt1.Rows[0]["VAT2"]) + 100) / 100), 2); VAT3 = Math.Round(Convert.ToDecimal((Convert.ToDecimal(dt1.Rows[0]["VAT3"]) + 100) / 100), 2); VAT4 = Math.Round(Convert.ToDecimal((Convert.ToDecimal(dt1.Rows[0]["VAT4"]) + 100) / 100), 2); VAT5 = Math.Round(Convert.ToDecimal((Convert.ToDecimal(dt1.Rows[0]["VAT5"]) + 100) / 100), 2); Status = dt1.Rows[0]["Status"].ToString(); Total = Math.Round(Convert.ToDecimal(Convert.ToDecimal(Qty1) * Convert.ToDecimal(Up1) + Convert.ToDecimal(Qty2) * Convert.ToDecimal(Up2) + Convert.ToDecimal(Qty3) * Convert.ToDecimal(Up3) + Convert.ToDecimal(Qty4) * Convert.ToDecimal(Up4) + Convert.ToDecimal(Qty5) * Convert.ToDecimal(Up5)), 2); GrandTotal = Math.Round(Convert.ToDecimal(((Convert.ToDecimal(Qty1) * Convert.ToDecimal(Up1)) * VAT1) + Convert.ToDecimal(Qty2) * Convert.ToDecimal(Up2) * VAT2 + Convert.ToDecimal(Qty3) * Convert.ToDecimal(Up3) * VAT3 + Convert.ToDecimal(Qty4) * Convert.ToDecimal(Up4) * VAT4 + Convert.ToDecimal(Qty5) * Convert.ToDecimal(Up5) * VAT5), 2); object[] added = { OrderID.ToString(),OrderDate.ToString() }; foreach (DataRow row in dt1.Rows) { dataGridReport.Rows.Add(added); }
Why i can't get each record in datagridview, why i get 1st record 4 times?
Thank you.