October 9, 2002 - Retrieving Product Categories from the IBuySpy Database
October 9, 2002 Retrieving Categories from the IBuySpy Database Tips: October 2002
Yehuda Shiran, Ph.D.
|
SqlConnection
object.
SqlCommand
object.
SqlDataReader
result to the caller.
Here's an example. The ProductsDB.js
file includes the method GetProductCategories()
.
As the name implies, this method retrieves the product categories from the database.
It follows the recipe above, calling the stored procedure ProductCategoryList
.
This stored procedure is the simplest one, as it doesn't expect any parameters.
It returns a table of all product categories in the databases. Here's the code:
public function GetProducts(categoryID: int) : SqlDataReader {
var myConnection : SqlConnection = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
var myCommand : SqlCommand = new SqlCommand("ProductsByCategory", myConnection);
myCommand.CommandType = CommandType.StoredProcedure;
var parameterCategoryID : SqlParameter = new SqlParameter("@CategoryID", SqlDbType.Int, 4);
parameterCategoryID.Value = categoryID;
myCommand.Parameters.Add(parameterCategoryID);
myConnection.Open();
var result : SqlDataReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
return result;
}