My toolset dB Layer

Source: Internet
Author: User

As a management software, we need to constantly deal with the database. Therefore, we need to encapsulate a set of DB-layer class libraries to make them comfortable.

The following class library is my own summary. This set of things is not very advanced in daily development,CodeIt's not so beautiful. I wrote it today and hope it will help you.

The class library is encapsulated on the basis of the Microsoft class library. Here we only introduce different things, as shown in-1.

Figure-1

It is an interface named after idbbase. as its name implies, it is a basic interface. Even if the backend database may be Oracle, sqlserver or access, there will still be something shared between them, this interface is used to encapsulate these public methods.

1. the splitstring and combosqlstring methods are used to parse SQL statements, that is, to split SQL statements into several subitems, so that they can be easily spliced later. this idea comes from the idea of PFC in Pb. Friends who have used PFC know that it provides an n_cst_ SQL class object, which is specially used to parse and split SQL statements.

2. the gettablebyvirtual method is interesting. It is used to create a virtual table. For example, if this table is not found in dB, a datatable object must be generated. Of course, datatable can be used. columns. the add () method is complete. if this method is used, select ''authorid, ''authorname, 0 sortorder from ad_virtual. note: The last ad_virtual table name must be added to identify whether a virtual table exists, but the ad_virtual table does not need to exist in the database!

3. When obtaining the DataSet object, the SQL statement is also different.-2 and figure-3 are shown.

Figure 2

Figure-3

Here, a wherestyle parameter is added. That is to say, SQL statements exist in three forms. One is to directly spell SQL statements, the other is to use parameterization, and the third is to format strings.

4. the SQL Execution method is shown in-4.

Figure 4

The dbsqlstringandparameter class is added. This class contains two attributes, as shown in-5. It is used to execute parameterized SQL statements, either single or batch.

Figure 5

5. The call method is reflected. DB type and connection string are directly taken from the configuration file.-6

Figure 6

6. obtain the table structure of accessdb. accessdb does not provide us with information such as sys in sqlserver. the objects in columns are used to store the DB objects created by users, and the related storage objects cannot be found when accessdb is enabled. we can get its dB object through-7, as shown in-7.

Figure-7

Another point is the log, including the DB table data change log and operation log. Here I use the log4net component and add it to the place where SQL statements are called.

There is nothing else, that is, some common methods are encapsulated. Let's take a look! I used to think about this set of things that were not prepared to publish the source code. Later I saw a lot of Daniel in the blog Park providing the source code selflessly. I am not a great guy, but I am also here to share the source code with others.

 

ArticleNavigation

My toolset dB Layer

Business Layer of my toolset

My toolkit UI Layer base & winform + example

My tool set UI Layer Webform ( Including Webpanel & jqueryeasyui Complete code ) + Display Example

 

Code address

Http://u.115.com/file/clwmyhqg #
Navi.kernel.dbutilities.rar

Extraction code:Clwmyhqg

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.