示例#1
0
        public static int Delete(PackageProdSupplier packagePS)
        {
            int           deletedRows = 0;
            SqlConnection conn        = TravelExpertsDB.GetConnection();
            string        sqlQuery    = "DELETE FROM Packages_Products_Suppliers " +
                                        "WHERE PackageId = @pkgID AND ProductSupplierId = @psID";
            SqlCommand cmd = new SqlCommand(sqlQuery, conn);

            cmd.Parameters.AddWithValue("@pkgID", packagePS.PackageID);
            cmd.Parameters.AddWithValue("@psID", packagePS.ProdSuppID);
            try
            {
                conn.Open();
                deletedRows += cmd.ExecuteNonQuery();
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                conn.Close();
            }

            return(deletedRows);
        }
示例#2
0
        public static bool Insert(PackageProdSupplier pkgProdSup)
        {
            bool successfulInsert = false;

            SqlConnection con       = TravelExpertsDB.GetConnection();
            string        insertSmt = "INSERT INTO Packages_Products_Suppliers (PackageId, ProductSupplierId) " +
                                      "VALUES(@pkgID, @psID)";
            SqlCommand cmd = new SqlCommand(insertSmt, con);

            cmd.Parameters.AddWithValue("@pkgID", pkgProdSup.PackageID);
            cmd.Parameters.AddWithValue("@psID", pkgProdSup.ProdSuppID);
            try
            {
                con.Open();
                successfulInsert = cmd.ExecuteNonQuery() >= 1; // run the insert command
            }
            catch (SqlException ex)
            {
                throw ex;
            }
            finally
            {
                con.Close();
            }

            return(successfulInsert);
        }