The Artima Developer Community
Sponsored Link

.NET Buzz Forum
Data Access Application Block

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Michael Mello

Posts: 100
Nickname: knarf
Registered: May, 2004

Michael Mello is .NET Web Developer
Data Access Application Block Posted: Jun 1, 2004 4:59 PM
Reply to this message Reply

This post originated from an RSS feed registered with .NET Buzz by Michael Mello.
Original Post: Data Access Application Block
Feed Title: melloblog
Feed URL: http://www.thauvin.net/errorpage.htm?aspxerrorpath=/Default.aspx
Feed Description: .NET and Everything After.
Latest .NET Buzz Posts
Latest .NET Buzz Posts by Michael Mello
Latest Posts From melloblog

Advertisement
The Data Access Application Block is a .NET component that is provided by Microsoft, which encapsulates data access functionality.  The wrapper class conforms to the best patterns and practices and provides methods for the major data access classes such as: SqlDataReader, DataSet, and the XMLReader.

Enough of the Data Access Application Block fluff; why should I use it?  The answer is simple; it cuts your data access code in half.  We all have come to know and love the great, ADO.NET, but let's face it ? it becomes very repetitive.  Here is just a small taste of how the DAAB can help you:

The following was taken from Examining the Data Access Application Block.

"In order to illustrate the advantage of using the Data Access Block, let's take a look at sample code that creates a SqlDataReader object and binds it to a DataGrid without using the Data Access Block. In general, returning a DataReader involves establishing a connection, creating a SqlCommand, and executing the command against the database. The resulting SqlDataReader object can then be bound to a DataGrid:"


//create the connection string  and sql to be executed
string strConnTxt = "Server=(local);Database=Northwind;Integrated Security=True;";
string strSql = "select * from products where categoryid = 1";

//create and open the connection object
SqlConnection objConn = new SqlConnection(strConnTxt);
objConn.Open();

//Create the command object
SqlCommand objCmd = new SqlCommand(strSql, objConn);
objCmd.CommandType = CommandType.Text;

//databind the datagrid by calling the ExecuteReader() method
DataGrid1.DataSource = objCmd.ExecuteReader();
DataGrid1.DataBind();

//close the connection
objConn.Close();



"Now lets look at the same task using the SqlHelper class's static ExecuteReader() method:"



//create the connection string and sql to be executed
string strSql = "select * from products where categoryid = 1";
string strConnTxt = "Server=(local);Database=Northwind;Integrated Security=True;";

DataGrid4.DataSource = SqlHelper.ExecuteReader(strConnTxt, CommandType.Text, strSql);
DataGrid4.DataBind();



I'm using current version 2.0 of the DAAB.  It has cut my repetitive code down drastically, and has really streamlined the way I interact with my SQL Server 2000 backend.  If you're current application isn't taking advantage of this .NET component, I suggest you read the documentation and download the Data Access Application Block for .NET.

Read: Data Access Application Block

Topic: DB Designer: design your Database Previous Topic   Next Topic Topic: Game Framework for the .NET Compact Framework

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use