Example Name: ProductsAdmin.asr
Language: ServerSide ActionScript
Version: 1.0.0
Code:
function getSearchResult(search) {
var sql = "SELECT ProductID, ProductName, UnitPrice,";
sql += " QuantityPerUnit, CategoryID, SupplierID";
sql += " FROM Products"
// If no argument is passed, all records returned--->
if(search)
sql += " WHERE ProductName LIKE '%" + search + "%'";
try {
var rsGetProducts = CF.query("northwind",sql);
}catch(e){
throw "There was a database error in getSearchResult()";
}
return rsGetProducts;
}
function addProduct(Product) {
var sql = "INSERT INTO Products ";
sql += " (ProductName";
sql += " , UnitPrice";
sql += " , QuantityPerUnit";
sql += " , CategoryID";
sql += " , SupplierID) ";
sql += " VALUES ";
sql += " ('" + Product.get("ProductName") + "'";
sql += " , " + Product.get("UnitPrice");
sql += " , '" + Product.get("QuantityPerUnit") + "'";
sql += " , " + Product.get("CategoryID");
sql += " , " + Product.get("SupplierID") + ")";
try {
CF.query("northwind",sql);
}catch(e){
throw sql//"There was a database error";
}
}
function updateProduct(Product) {
var sql = "UPDATE Products";
sql += " SET ProductName='" + Product.get("ProductName") + "'";
sql += " , UnitPrice=" + Product.get("UnitPrice");
sql += " , QuantityPerUnit='" + Product.get("QuantityPerUnit") + "'";
sql += " , CategoryID=" + Product.get("CategoryID");
sql += " , SupplierID=" + Product.get("SupplierID");
sql += " WHERE ProductID = " + Product.get("ProductID");
try {
CF.query("northwind",sql);
}catch(e){
throw sql;//"There was a database error";
}
}
function deleteProducts(ProductIDs) {
// var sql = "DELETE FROM Products WHERE ProductID IN (" + productids + ")";
var sql= "UPDATE Products SET Discontinued = 1 WHERE ProductID IN (" + ProductIDs + ")";
try {
CF.query("northwind",sql);
}catch(e){
throw sql//"There was a database error";
}
}
function getCategories() {
var sql = "SELECT CategoryID, CategoryName FROM Categories";
try {
var rsCategories = CF.query("Northwind", sql);
}catch(e){
throw "There was a database error";
}
return rsCategories;
}
function getSuppliers() {
var sql = "SELECT SupplierID, CompanyName FROM Suppliers";
try {
var rsSuppliers = CF.query("Northwind", sql);
}catch(e){
throw "There was a database error";
}
return rsSuppliers;
}
Download code text
Download chapter example files