database table additions and deletions help class

Source: Internet
Author: User

1. Purpose

Use the ADO to connect SQL Server database, delete and change the data table.

2. Requirements

Pass in SQL statements and parameters to get a result set or dictionary set

3. Approach to implementation

Encapsulates the parameterized method and the SqlDataReader value method of the ADO object, adds the passed-in parameter to the SqlParameter, and places the fetched value in the dictionary set or the object list

Parameter name is found by locating the parameter ID in the SQL statement, and the parameter value is found by the name or the location passed in by the parameter. Then join SqlParameter.

When values are fetched, each row of data is read by SqlDataReader, with the column name key and the value added to the dictionary list. or find the corresponding entity class property name based on the column name, then assign a value.

Use the regular to find the parameter names in the SQL statement. Use the PropertyInfo class to find the corresponding attribute of the entity class based on the parameter name, and then take the assignment.

Close the database connection after executing the statement, and open the database connection before executing the statement. If there is a transaction, open the connection when the transaction Start method is invoked, and close the connection after the rollback or commit.

4. How to use

SQL Server Db=new SQL Server (CONNSTR);

String sql= "Select name from Employee where Id=:id and Isdel=:isdel";

Employee[] Data=db. Executequery<employee> (sql,1,0)

5. Source code

Https://github.com/mirrortom/DBM

database table additions and deletions help class

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.