Foros del Web » Programación para mayores de 30 ;) » .NET »

new SqlDataReader

Estas en el tema de new SqlDataReader en el foro de .NET en Foros del Web. Hola amigos foreros, cómo andan? Estoy necesitando una manito en .NET. Resulta que me pasaron un proyecto para migrar la conección a la DB, antiguamente ...
  #1 (permalink)  
Antiguo 13/06/2014, 07:17
Avatar de mikolbe  
Fecha de Ingreso: octubre-2010
Mensajes: 104
Antigüedad: 13 años, 7 meses
Puntos: 2
new SqlDataReader

Hola amigos foreros, cómo andan?

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
  1. class SQLDataReaderBull
  2.     {
  3.         private SqlDataReader DataReader;
  4.         private List<SqlDataReader> PreviousRow = new List<SqlDataReader>();
  5.  
  6.  
  7.         #region CONSTRUCTOR
  8.             public SQLDataReaderBull(SqlDataReader dReader)
  9.             {
  10.                 this.DataReader = dReader;
  11.             }
  12.         #endregion
  13.  
  14.         #region PROPIEDADES
  15.             public SqlDataReader sqldataReader
  16.             {
  17.                 get { return DataReader; }
  18.                 set
  19.                 {
  20.                     int i = 0;
  21.                     for (i=0; i < this.PreviousRow.Count; i++)
  22.                     {
  23.                         this.PreviousRow.RemoveAt(0);
  24.                     }
  25.  
  26.                     DataReader = value;
  27.                 }
  28.             }
  29.  
  30.             public bool EOF
  31.             {
  32.                 get
  33.                 {
  34.                     SqlDataReader aux = this.DataReader;
  35.  
  36.                     return !aux.Read();
  37.                 }
  38.             }
  39.  
  40.             public bool BOF
  41.             {
  42.                 get
  43.                 {
  44.                     return (PreviousRow.Count == 0);
  45.                 }
  46.             }
  47.  
  48.  
  49.             /// <summary>
  50.             /// REVISAR ESTE METODO
  51.             /// </summary>
  52.             public int RowCount
  53.             {
  54.                 get
  55.                 {
  56.                     int rowCount = this.DataReader.Cast<Object>().Count();
  57.                     return rowCount;
  58.                 }
  59.             }
  60.  
  61.             public object this[int i]
  62.             {
  63.                 get
  64.                 {
  65.                     return this.DataReader[i];
  66.                 }
  67.             }
  68.  
  69.             public object this[string name]
  70.             {
  71.                 get
  72.                 {
  73.                     return this.DataReader[name];
  74.                 }
  75.             }
  76.  
  77.            
  78.         #endregion
  79.  
  80.  
  81.         #region METODOS
  82.             public void Close()
  83.             {
  84.                 DataReader.Close();
  85.             }
  86.  
  87.             public void Move(int Row)
  88.             {
  89.  
  90.                 int cantidad = this.PreviousRow.Count - Row;
  91.                 this.DataReader = this.PreviousRow[Row];
  92.                 this.PreviousRow.RemoveRange(Row, cantidad);
  93.  
  94.             }
  95.  
  96.             public void Cancel()
  97.             {
  98.                 this.Close();
  99.             }
  100.  
  101.             public bool MovePrevious()
  102.             {
  103.                 if (!this.BOF)
  104.                 {
  105.                     int indice = this.PreviousRow.Count - 1;
  106.                     this.DataReader = this.PreviousRow[indice];
  107.                     this.PreviousRow.RemoveAt(indice);
  108.                 }
  109.                 else
  110.                 {
  111.                     return false;
  112.                 }
  113.                 return true;
  114.             }
  115.  
  116.             public bool MoveNext()
  117.             {
  118.                 this.PreviousRow.Add(this.DataReader);
  119.  
  120.                 return this.DataReader.Read();
  121.             }
  122.  
  123.             public bool Read()
  124.             {
  125.                 this.PreviousRow.Add(this.DataReader);
  126.  
  127.                 return this.DataReader.Read();
  128.             }
  129.  
  130.             public void MoveLast()
  131.             {
  132.                 while (this.DataReader.Read())
  133.                 {
  134.                     this.PreviousRow.Add(this.DataReader);
  135.                 }
  136.             }
  137.  
  138.             public void MoveFirst()
  139.             {
  140.                 this.DataReader = this.PreviousRow[0];
  141.  
  142.                 for (int i = 0; i < this.PreviousRow.Count; i++)
  143.                 {
  144.                     this.PreviousRow.RemoveAt(0);
  145.                 }
  146.  
  147.             }
  148.         #endregion
  149.  
  150.     }

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]]>>

Etiquetas: net
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 01:33.