Hi Alex,
The DAAB(Data Access Application Block) provided by the Enterprise Library
is the DAL itself so we don't have to write our own DAL. What we need is to
write the BLL.
I'd like to demonstrate how to use DAAB in ASP.NET with the following
sample.
1. Create a new ASP.NET web site in Visual Studio 2005. The database used
in the sample is the Northwind database.
2. Please make sure you've correctly configured the connection string,
provider, etc. You can refer to the following article to learn how to do
this:
http://msdn.microsoft.com/en-us/library/cc309171.aspx
3. Add a new class BLL.cs in the web site and paste following code into the
class file:
public class BLL
{
public DataSet CustOrdersDetail(Int32 orderid)
{
Database db = DatabaseFactory.CreateDatabase();
string sqlCommand = "CustOrdersDetail";
DbCommand dbCommand = db.GetStoredProcCommand(sqlCommand);
db.AddInParameter(dbCommand, "OrderID", DbType.Int32, orderid);
DataSet productDataSet = db.ExecuteDataSet(dbCommand);
return productDataSet;
}
public DataSet CustOrder()
{
Database db = DatabaseFactory.CreateDatabase();
DbCommand dbCommand = db.GetSqlStringCommand("Select * from
Orders");
DataSet orderDataSet =db.ExecuteDataSet(dbCommand);
return orderDataSet;
}
}
4. Open Default.aspx and paste following code in the aspx file:
<asp:GridView ID="GridView1" runat="server"
DataSourceID="ObjectDataSource1" SelectedRowStyle-BackColor="Pink"
DataKeyNames="OrderID" AutoGenerateSelectButton="true" AllowPaging="true"
PageSize="5">
</asp:GridView>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
TypeName="BLL" SelectMethod="CustOrder">
</asp:ObjectDataSource>
<asp:GridView ID="GridView2" runat="server"
DataSourceID="ObjectDataSource2">
</asp:GridView>
<asp:ObjectDataSource ID="ObjectDataSource2" runat="server"
TypeName="BLL" SelectMethod="CustOrdersDetail">
<SelectParameters>
<asp:ControlParameter ControlID="GridView1" Name="orderid"
/></SelectParameters>
</asp:ObjectDataSource>
5. View the Default.aspx page. You can select a row of the first table to
view the details information on the second table.
The above sample uses the DAAB provided by the Enterprise Library 3.1 as
the DAL. Then write a BLL by ourselves to use the DAAB. The final effect is
a typical master-details scenario. Here two GridViews are used to render
the table.
You can learn more about the the Enterprise Library 3.1 from MSDN:
http://msdn.microsoft.com/en-us/library/cc309205.aspx
Please have a try and let me know if it works. If you need further
assistance please feel free to ask.
Regards,
Allen Chen
Microsoft Online Community Support
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
.
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subs...#notifications.
Note: MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 2 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions. Issues of this
nature are best handled working with a dedicated Microsoft Support Engineer
by contacting Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/en-us/subs.../aa948874.aspx
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.