Estoy necesitando una manito en .NET.
Resulta que me pasaron un proyecto para migrar la conección a la DB, antiguamente se utilizaba RDO y ahora quieren utilizar SQLClient. Lo que me está sucediendo es que todas las variables RecordSets tienen métodos y propiedades que SQLDataReader no tiene. Entonces tuve la magnífica idea de crear una clase que al instanciarla se le pase por parámetros el SqlDataReader y que contenga los métodos que tiene el RecordSet aplicando la lógica correspondiente....
¿Para qué hice esto?
Por que sino tenía que tocar todo el fuente.
Por ejemplo:
una de las propiedades que no tiene el SqlDataReader y si lo tiene el RecordSet es el clásico End Of File (EOF), por lo que mi clase tiene esa propiedad y dentro del get hice la programación correspondiente.
Este es el código de mi clase en C#
Código C:
Ver original
class SQLDataReaderBull { private SqlDataReader DataReader; private List<SqlDataReader> PreviousRow = new List<SqlDataReader>(); #region CONSTRUCTOR public SQLDataReaderBull(SqlDataReader dReader) { this.DataReader = dReader; } #endregion #region PROPIEDADES public SqlDataReader sqldataReader { get { return DataReader; } set { int i = 0; for (i=0; i < this.PreviousRow.Count; i++) { this.PreviousRow.RemoveAt(0); } DataReader = value; } } public bool EOF { get { SqlDataReader aux = this.DataReader; return !aux.Read(); } } public bool BOF { get { return (PreviousRow.Count == 0); } } /// <summary> /// REVISAR ESTE METODO /// </summary> public int RowCount { get { int rowCount = this.DataReader.Cast<Object>().Count(); return rowCount; } } public object this[int i] { get { return this.DataReader[i]; } } public object this[string name] { get { return this.DataReader[name]; } } #endregion #region METODOS public void Close() { DataReader.Close(); } public void Move(int Row) { int cantidad = this.PreviousRow.Count - Row; this.DataReader = this.PreviousRow[Row]; this.PreviousRow.RemoveRange(Row, cantidad); } public void Cancel() { this.Close(); } public bool MovePrevious() { if (!this.BOF) { int indice = this.PreviousRow.Count - 1; this.DataReader = this.PreviousRow[indice]; this.PreviousRow.RemoveAt(indice); } else { return false; } return true; } public bool MoveNext() { this.PreviousRow.Add(this.DataReader); return this.DataReader.Read(); } public bool Read() { this.PreviousRow.Add(this.DataReader); return this.DataReader.Read(); } public void MoveLast() { while (this.DataReader.Read()) { this.PreviousRow.Add(this.DataReader); } } public void MoveFirst() { this.DataReader = this.PreviousRow[0]; for (int i = 0; i < this.PreviousRow.Count; i++) { this.PreviousRow.RemoveAt(0); } } #endregion }
Lo que me está pasando es que no puedo crear una nueva instancia del SQLDataReader que recibo en el constructor, por ejemplo en la propiedad EOF, creo una variable auxiliar de tipo SQLDataReader, y lo que necesito es que esa variable apunte a otro espacio en memoria y no al mismo espacio que ocupa el SQLDataReader que recibí por parámetro.
¿Hay alguna manera de crear una nueva instancia de la variable "aux" y que no apunte a la misma dirección de memoria y se cree una copia del SqlDataReader?
Desde ya, muchas gracias.
<<[[Mikol Be]]>>