public static int PlaceOrder(Order o, List <OrderItem> listOI) { dbcon obj = new dbcon(); SqlParameter[] objParams = new SqlParameter[14]; objParams[0] = new SqlParameter("@CustomerID", o.CustomerID); objParams[1] = new SqlParameter("@OrderDate", o.OrderDate); objParams[2] = new SqlParameter("@FirstName", o.FirstName); objParams[3] = new SqlParameter("@LastName", o.LastName); objParams[4] = new SqlParameter("@Company", o.Company); objParams[5] = new SqlParameter("@Address", o.Address); objParams[6] = new SqlParameter("@Country", o.Country); objParams[7] = new SqlParameter("@City", o.City); objParams[8] = new SqlParameter("@Province", o.Province); objParams[9] = new SqlParameter("@ZipCode", o.ZipCode); objParams[10] = new SqlParameter("@Telephone", o.Telephone); objParams[11] = new SqlParameter("@Fax", o.Fax); objParams[12] = new SqlParameter("@totalAmount", o.TotaAmount); objParams[13] = new SqlParameter("@Status", o.status); o.OrderID = int.Parse(obj.ExecuteScalar("InsertOrder", objParams).ToString()); foreach (OrderItem item in listOI) { SqlParameter[] objParams2 = new SqlParameter[7]; objParams2[0] = new SqlParameter("@OrderID", o.OrderID); objParams2[1] = new SqlParameter("@ProductID", item.ProductID); objParams2[2] = new SqlParameter("@Quantity", item.Quantity); objParams2[3] = new SqlParameter("@UnitCost", item.UnitCost); objParams2[4] = new SqlParameter("@PurchaseDate", DateTime.Now); objParams2[5] = new SqlParameter("@ProductName", item.ProductName); objParams2[6] = new SqlParameter("@buyprice", item.buyPrice); obj.ExecuteNonQuery("InsertOrderItem", objParams2); } return(o.OrderID); }