Creating a Business Logic Layer


F

Frank

I have read and followed Scott Mitchells' tutorial, Creating a 'Business
Logic Layer', @
http://www.asp.net/learn/dataaccess/tutorial02cs.aspx?tabid=63, and it
occurred to me that he did not include the InsertProduct("New Product", 1,
1, "12 tins per carton", 14.95m, 10, 0, 10, false) function in the BLL.

Prior to implementing the BLL, in the presentation layer I captured the new
ProductID from DLL's InsertProduct function, which implements SELECT
SCOPE_IDENTIFIER(), with:

new_ProductID = Convert.ToInt32(productsAdapter.InsertProduct("New Product",
1, 1, "12 tins per carton", 14.95m, 10, 0, 10, false));

This worked well. When I next tried to implement the same function in the
BLL like so:

[System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select,
false)]

public Northwind.ProductsDataTable InsertProduct(String ProductName, Int32?
SupplierID, Int32? CategoryID, string quantityPerUnit, decimal? unitPrice,
short? unitsInStock, short? unitsOnOrder, short? reorderLevel, bool
discontinued)

{

return Adapter.InsertProduct(ProductName, SupplierID, CategoryID,
quantityPerUnit, unitPrice, unitsInStock, unitsOnOrder, reorderLevel,
discontinued);

}

I get the following error:

Error 1 Cannot implicitly convert type 'object' to
'Northwind.ProductsDataTable'. An explicit conversion exists (are you
missing a cast?)



I realize that this function in the DLL returns and int32 which represents
the ProductID of the newly inserted product, and so I tried to cast, as I
did in the presentation layer which worked with the DLL, like so:



[System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select,
false)]

public Northwind.ProductsDataTable InsertProduct(String ProductName, Int32?
SupplierID, Int32? CategoryID, string quantityPerUnit, decimal? unitPrice,
short? unitsInStock, short? unitsOnOrder, short? reorderLevel, bool
discontinued)

{

return Convert.ToInt32(Adapter.InsertProduct(ProductName, SupplierID,
CategoryID, quantityPerUnit, unitPrice, unitsInStock, unitsOnOrder,
reorderLevel, discontinued) );

}



But then I get:

Error 1 Cannot implicitly convert type 'int' to
'Northwind.ProductsDataTable'

Any suggestions how I might resolve this problem? Thanks in advance
 
Ad

Advertisements

C

Chris Dunaway

Frank wrote:

[System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select,
false)]

public Northwind.ProductsDataTable InsertProduct(String ProductName, Int32?
SupplierID, Int32? CategoryID, string quantityPerUnit, decimal? unitPrice,
short? unitsInStock, short? unitsOnOrder, short? reorderLevel, bool
discontinued)

{

return Convert.ToInt32(Adapter.InsertProduct(ProductName, SupplierID,
CategoryID, quantityPerUnit, unitPrice, unitsInStock, unitsOnOrder,
reorderLevel, discontinued) );

}



But then I get:

Error 1 Cannot implicitly convert type 'int' to
'Northwind.ProductsDataTable'

The InsertProduct method you show above returns type
Northwind.ProductsDataTable. Why are you trying to return a type of
Int32? What type does Adapter.InsertProduct return?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top