Comparison of Two Methods for SQLServer connection in DotNet Development

Source: Internet
Author: User

In.. net. data. in the SqlClient namespace, I believe many people use this method for programming, and Microsoft. applicationBlocks. data. in the SqlHelper namespace, the methods are roughly the same. Why are two different spaces providing similar functions?

Microsoft is launching. by default, the System and Microsoft namespaces are attached to the. net System. Microsoft namespaces are powerful supplements to the System namespaces. data. to program SqlClient, you need to use SqlCommand and SqlDataAdapter. You need to manage the database to open and close, for example

Cn. open (); // open the database connection
SqlDataReader dr = cmd. ExecuteReader (CommandBehavior. CloseConnection); // close the connection when the dataset is closed.
Dr. Close (); // Close the dataset (the database connection is also disabled)

However, in the Microsoft. ApplicationBlocks. Data. SqlHelper namespace, the same operation is not required.

SqlDataReader dr = SqlHelper. ExecuteReader (cn, CommandType. Text, querySql );

Two-phase comparison, the following is more satisfactory, isn't it?

Since programming in Microsoft's system, the best choice of course is to maximize the use of what Microsoft provides ,.. net System. similar to a secondary development product that provides the basic functions of net, its further optimized functions are naturally not limited to database development. It also takes more time to study these functions, this product is still open-source. If you are interested, you can download it on msdn. Now it is in version 2.0.

I hope those who have profound insights will teach me this.

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.