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