Asp. The design of net database operation layer

Source: Internet
Author: User

In doing development, often need to access the database, each repeated writing Connection,command and other statements is a boring thing, we should have had this experience. Now I have designed the database operating layer to share with you, learn from each other. I personally prefer to put their own design methods, design ideas to write out, mutual sharing and exchanges, to complement each other, can be more perfect their own design.

In. NET, the database is divided into three types. Is it really divided into three types of databases? I was guessing, according to. NET provides the database operation class guess, if not, just let me not say it.

The first type is Microsoft's default database type, SQL Server.

The second type is Oracle.

The third type is OLE DB, such as Access,mysql and so on. Of course, it also supports SQL Server and Oracle, just not so good.

My design is simple, because there are three different types of databases, so define an interface Idbhelper:

IDBHelper.cs

Code
using System;
Using System.Text;
Using System.Data;
Namespace Pride.dbhelper
{
///<summary>
///Author: Really proud
///time: September 5, 2008
///Name: Database operation Layer Interface 
  ///</summary> Public
interface Idbhelper
{
DataTable ExecuteReader (String connectionstr    ING, commandtype cmdtype, string cmdtext);
int Executenonequery (String connectionString, CommandType cmdtype, string cmdtext);
Object ExecuteScalar (String connectionString, CommandType cmdtype, string cmdtext);
<summary>
///Add SQL statement parameters
///</summary>
///<param name= "Sqlparams" >
  
   ///Sqlparam is a class that is used to hold parameters that are named and 傎
///</param>
void Addparameter (params sqlparam[) sqlparams);  >///<summary>
///empty parameter variable list
///</summary>
void Resetparameter ();
}
}
  

The name of the method is named according to the three actions of the command class, and the function is similar to theirs. The ExecuteReader method returns the DataTable class, which is able to disconnect from the database in time, in accordance with the principle of opening as late as possible.

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.