Use VS. NET to create. NET reusable database components

Source: Internet
Author: User
The introduction of Microsoft's. NET architecture provides a powerful tool for us to build a distributed application system. Compared with the COM component of traditional Windows applications,. NET component development is much simpler and quicker. In addition, the deployment of components does not need to be marked in the registry as the COM component. The. NET component only needs to be copied to the corresponding folder.
Next we will use the integrated development tool Visual Studio. NET of the. NET program to actually develop an Access2000 database access component and reuse it in another ASP. NET application system.
(1) component creation
Start VS. NET, create a Visual C # Project, and select "class library" as the template ". See figure 1.
In this way, a new folder ClassLibrary1 is generated under "My Documents" Visual Studio Projects on our machine. And automatically generate the Class1.cs file:
Using System;
Namespace ClassLibrary1
{
/// <Summary>
/// Summary of Class1.
/// </Summary>
Public class Class1
{
Public Class1 ()
{
//
// TODO: add the constructor logic here
//
}
}
}

Because the component we will generate is related to data access, you must add the Database Reference statement:
Using System. Data;
Using System. Data. OleDb;
In addition, we can change the namespace to myDB and the class name to myDbLink. Then we define three attributes to make our code more universal:
Public string sDbPath = ""; // database path (including database name)
Public string sDbTable = ""; // table name
Public string sPassword = ""; // database password
The getData () method in the myDbLink class returns the view of the queried table. The complete code after customization is as follows:
Using System;
Using System. Data;
Using System. Data. OleDb;

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.