Microsoft application blocks for. Net (3)

Source: Internet
Author: User
Tags custom name
Internal Design
The Data Access Application Block contains the complete Source code And a comprehensive guide to its design. This section describes the main implementation details.

 

Sqlhelper class Implementation Details
The sqlhelper class is used to encapsulate data access through a set of static methods. This class cannot be inherited or instantiated, so it is declared as a non-inherited class that contains a dedicated constructor.

 

Each method implemented in the sqlhelper class provides a set of consistent overloading. This provides a good way to use the sqlhelper class to execute commands. It also provides necessary flexibility for developers to select a way to access data. Each method overload supports different method parameters, so developers can determine how to pass connection, transaction, and parameter information. The methods implemented in the sqlhelper class include:

 

Executenonquery. This method is used to execute commands that do not return any rows or values. These commands are usually used to execute database updates, but can also be used to return output parameters of stored procedures.
Executereader. This method is used to return the sqldatareader object, which contains the result set returned by a command.
Executedataset. This method returns the DataSet object, which contains the result set returned by a command.
Executescalar. This method returns a value. This value is always the first column in the first line returned by the command.
Executexmlreader. This method returns the XML fragment of the for XML query.
In addition to these common methods, the sqlhelper class also contains some special functions for managing parameters and preparing commands to be executed. Regardless of the method implementation called by the client, all commands are executed through the sqlcommand object. Before the sqlcommand object can be executed, all parameters must be added to the parameters set, and the connection, commandtype, commandtext, and transaction attributes must be correctly set. The special functions in the sqlhelper class are mainly used to provide a consistent method for issuing commands to the SQL Server database without considering client applications.ProgramCall the implementation of the overload method. The special utility functions in the sqlhelper class include:

 

Attachparameters: This function is used to connect all necessary sqlparameter objects to the running sqlcommand.
Assignparametervalues: This function is used to assign values to sqlparameter objects.
Preparecommand: This function is used to initialize command attributes (such as connection and transaction environment.
Executereader: This dedicated executereader implementation is used to open the sqldatareader object through the appropriate commandbehavior, so as to most effectively manage the validity period of the connection associated with the reader.
Sqlhelperparametercache class Implementation Details
The parameter array is cached in the dedicated hashtable. The parameters retrieved from the cache are replicated internally, so that the client application can change the parameter values and perform other operations without affecting the cached parameter arrays. The dedicated sharing Function cloneparameters can achieve this purpose.

 

FAQs
What new features are included in this version?
Compared with Data Access Application Block beta 2.0, this RTM version includes the following new features and changes:

 

The sqlhelper method does not need the sqlconnection parameter for transactional overload. In this version, the connection information is derived from the sqltransaction object, so you do not need to include the sqlconnection object parameter in the method signature.
Now, the getspparameterset method uses the deriveparameters method of the ADO. Net commandbuilder class to determine the parameters required for the stored procedure. This is more efficient than querying the database directly in Beta 2.0.
Can xcopy be used to deploy the data access application block assembly?
Yes. Microsoft. applicationblocks. Data. dll assembly can be deployed using xcopy after compilation.

 

When should I use the executedataset method and the executereader method?
In fact, when should multiple data rows in the DataSet object be returned and datareader be used. The answer depends on your application's specific needs and your choice between flexibility and original performance. Dataset provides you with a flexible and disconnected view of data, while datareader provides you with a superior performance, read-only, forward cursor only. For more information about dataset and datareader, see Data Access architecture guide ).

 

How can I use executedataset to return a dataset containing multiple tables?
Create a stored procedure that can return multiple row sets (by executing multiple select statements or calling other stored procedures in a nested manner) and run the procedure using the executedataset method, you can retrieve datasets that contain multiple tables.

 

For example, assume that your database contains the following stored procedures.

 

Create procedure getcategories
As
Select * from categories
Go
Create procedure getproducts
As
Select * from products

You can create a primary Stored Procedure for nested calling of these processes, as shown in the following figure:CodeExample.

 

Create procedure getcategoriesandproducts
As
Begin
Exec getcategories
Exec getproducts
End

Executing this primary stored procedure using the executedataset method returns a dateset containing two tables: one containing the classified data and the other containing the product data.

 

Note:

The executedataset method does not provide a method to specify a custom name for the returned table. The number of the first table is always 0, the name is table, the number of the second table is 1, and the name is Table1.
Are there other application blocks?
Data Access Application Block is one of the several application blocks to be released. These application blocks can solve common problems encountered by developers in different projects. They can be quickly and conveniently inserted into. NET applications.

 

Feedback and support
If you have any questions, comments, or suggestions about the Data Access Application Block, please email the devfdbck@microsoft.com and we will provide feedback in a timely manner.

 

Application blocks for. NET is designed to assist in the development of. Net distributed applications. The sample code and documentation are provided as they are. Although we have been tested and considered a stable code set, we do not provide support for it as traditional Microsoft products do.

 

We have also created a newsgroup to help you use application blocks for. Net (. NET application block ). You can consult with colleagues, colleagues, and Microsoft support experts in online open forums.

 

Others can also benefit from your questions and comments. Our development team will view newsgroups every day:
News group: web-based readers
Http://msdn.microsoft.com/newsgroups/loadframes.asp? ICP = msdn & slcid = US & newsgroup = Microsoft. Public. DOTNET. distributed_apps)

 

Newsgroup: NNTP Reader
News: // msnews.microsoft.com/microsoft.public.dotnet.distributed_apps)

 

Do you want to learn and use. NET functions? You are welcome to work with Microsoft technology centers technical experts to learn the best development experience. For details, visit the http://www.microsoft.com/business/services/mtc.asp ).

 

Do you need more help? Please visit the new customer support service advisory services. This solution can meet your small-scale consulting needs. For more information about advisory services, visit the http://support.microsoft.com/default.aspx? SCID = FH; en-US; offer58 & Fr = 0 & SD = gn & Ln = en-US & Ct = SD & SE = Nona (English ).

 

More information
The Design and Development of Data Access Application Block is based on the best development experience and general design principles discussed in the data access in. NET architecture Guide (English. Read this guide to learn more about data access.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.