Κοιτώντας χτές την "αποθήκη" κώδικά μου ( τι ψώνιο ε; :D ), βρήκα ένα μικρό utility class, το οποίο λειτουργεί σαν ένας page-able read-ony navigable Reader.
Το λέω BaseResultSet, και βασικά μιμείται το ResultSet class της Java ( αχ ... μου ξανάρχονται ένα-ένα, χρόνια δοξασμένα ... ).
Χρησιμοποιείται κάπως έτσι:
static void TestResultSet(){
IDbConnection
objConn = _sourceMan.GetConnectionByName("local_odbc");
BaseResultSet
rs = new BaseResultSet("select * from
users", objConn);
rs.Open();
while(rs.Next()){
Console.WriteLine("User
ID: {0}", rs.Get("uname"));
}
rs.Close();
}
static void
TestResultSetPaged(int pageSize){
IDbConnection
objConn = _sourceMan.GetConnectionByName("local_odbc");
BaseResultSet
rs = new BaseResultSet("select * from
users", objConn, pageSize);
rs.Open();
while(rs.NextPage()){
Console.WriteLine("Page:
{0}", rs.CurrentPage);
while(rs.Next()){
Console.WriteLine("User
ID: {0}", rs.Get("uname"));
}
}
rs.Close();
}
... αυτές είναι οι δύο μέθοδοι με τις οποίες έκανα τότε debug προφανώς, και δείχνουν τη χρήση του σε paged / non-paged mode.
Το interface το οποίο υλοποιεί, είναι το παρακάτω:
public
interface IResultSet : IListSource, IEnumerable
{
/* Row Count */
int Count {get;}
/* Current page index */
int CurrentPage {get;}
/* Total Page Count */
int PageCount {get;}
/* Size of each page */
int PageSize {get; set;}
/* Moves the r/set cursor to the specified page */
bool MoveToPage(int
intPageNo);
/* Move to first row ( or first row in the current page ) */
void First();
/* Move to the last row ( or last row in the current page )
*/
void Last();
/* Move to the next row ( or the next row in the current
page ) */
bool Next();
/* Move to the previous row ( or the previous row in the
current page ) */
bool Previous();
/* Get the value in the current row, at the specified index
*/
object Get(int
index);
/* The value of column columnName at the current row */
object Get(string
columnName);
/* Fill the recordset */
bool Open();
bool Close();
/* Return the ResultSet ( or current page ) as an Xml
string */
string XmlString {get;}
/* Return the ResultSet ( or current page ) as an
XmlDocument */
System.Xml.XmlDocument
XmlDocument {get;}
// IListSource members
bool ContainsListCollection {get;}
IList GetList();
// IEnumerable members
IEnumerator
GetEnumerator();
}
Στα συνημμένα έχω τα sources, για όποιον θέλει αν το δεί λίγο, γιατί είμαι σίγουρος οτι γίνεται χαμός εκει μέσα αλλά ίσως φανεί χρήσιμο σε κάποιον.
Πολύ καλή μέρα μας
Angel
O:]