Пример #1
0
        public static int InsertPackagesProductSuppliers(PackagesProductSuppliers newPackagesProductSuppliers)

        {
            int yay = 0;

            //using package db to initialize connection
            DBCall.InitSQL();

            using (SqlConnection conn = new SqlConnection(DBCall.builder.ConnectionString))
            {
                string insertStatement = "INSERT INTO Packages_Products_Suppliers(PackageId, ProductSupplierId) VALUES(@PackageId, @ProductSupplierId)";

                SqlCommand cmd = new SqlCommand(insertStatement, conn);

                //Takes values from the main page and puts into database
                cmd.Parameters.AddWithValue("@PackageId", newPackagesProductSuppliers.PackageId);
                cmd.Parameters.AddWithValue("@ProductSupplierId", newPackagesProductSuppliers.ProductSupplierId);


                try
                {
                    conn.Open();
                    yay = cmd.ExecuteNonQuery(); //run DML statements
                }
                catch (SqlException ex)
                {
                    throw ex;
                }
                finally
                {
                    conn.Close();
                }
            }
            return(yay);
        }
Пример #2
0
//Call the insert into packages product suppliers and add the packageId and productsupplier Id
        private void btnAddProduct_Click(object sender, EventArgs e)
        {
            newPackagesProductSuppliers                   = new PackagesProductSuppliers();
            newPackagesProductSuppliers.PackageId         = Convert.ToInt32(cboPackId.Text);
            newPackagesProductSuppliers.ProductSupplierId = Convert.ToInt32(cboSupplierList.SelectedValue);


            int NAY = 0;

            NAY = PackagesProductSuppliersDB.InsertPackagesProductSuppliers(newPackagesProductSuppliers);

            if (NAY == 1)
            {
                MessageBox.Show("Package and Product has been inserted");
            }
            else
            {
                MessageBox.Show("Error. Package and product has not been inserted");
            }
        }