private void insertInvoice_Product(Invoice invoice) { DataTable dt = (DataTable)dgInvoiceProduct.DataSource; for (int i = 0; i < dt.Rows.Count; i++) { int quantity = 0; decimal price = 0; decimal totalPrice = 0; decimal serviceCharge = 0; bool subCon = false; string description = dt.Rows[i]["Description"].ToString(); string categoryName = dt.Rows[i]["Name"].ToString(); //Category selectedCategory = BLCategory.GetCategoryById(APCContext, categoryId); Category selectedCategory = BLCategory.GetCategoryByExactName(APCContext, categoryName); Kurs selectedKurs = BLKurs.GetKursByExactName(APCContext, dt.Rows[i]["Kurs"].ToString()); int.TryParse(dt.Rows[i]["Quantity"].ToString(), out quantity); decimal.TryParse(dt.Rows[i]["Price"].ToString(), out price); decimal.TryParse(dt.Rows[i]["Total"].ToString(), out totalPrice); decimal.TryParse(dt.Rows[i]["ServiceCharge"].ToString(), out serviceCharge); bool.TryParse(dt.Rows[i]["SubCon"].ToString(), out subCon); BLInvoice_Product.insertInvoice_Product(APCContext, invoice, selectedCategory, description, quantity, dt.Rows[i]["Unit"].ToString(), price, selectedKurs, serviceCharge, totalPrice, subCon); } }