A simple implementation of converting datareader into Ables

Source: Internet
Author: User
Many implementations of converting datareader into Ables or dataset are usually implemented through loop traversal. Now there is a simpler method. Using the dbdataadapter class, dataadapters of all providers inherit from it. It contains a fill method and requires an idatareader parameter. We can create a class that inherits from it to call this method. It is very easy to convert a datareader into a able. However, other abstract methods must be overwritten. See the following code:

1 using system;
2 using system. Data;
3 using system. Data. Common;
4
5 namespace midapex. smartorm
6 {
7 class datareaderadapter: dbdataadapter
8 {
9 Public int fillfromreader (datatable, idatareader datareader)
10 {
11 return this. Fill (datatable, datareader );
12}
13
14 // The following methods need to be overwritten
15 protected override rowupdatedeventargs createrowupdatedevent (
16 datarow,
17 idbcommand command,
18 statementtype,
19 datatablemapping tablemapping
20) {return NULL ;}
21
22 protected override rowupdatingeventargs createrowupdatingevent (
23 datarow,
24 idbcommand command,
25 statementtype,
26 datatablemapping tablemapping
27) {return NULL ;}
28
29 protected override void onrowupdated (
30 rowupdatedeventargs Value
31 ){}
32 protected override void onrowupdating (
33 rowupdatingeventargs Value
34 ){}
35}
36}

This class can be instantiated in actual use. It is very easy to call this method for conversion.

Http://www.eggheadcafe.com/PrintSearchContent.asp? Linkid = 628

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.