Pasar DataReader a DataSet

28/04/2004 - 09:30 por Asier | Informe spam
Hola grupo,

¿Como puedo pasar el contenido de un DataReader a un DataSet?

Gracias
 

Leer las respuestas

#1 Angel. E. Ruiz. Pastor
29/04/2004 - 01:53 | Informe spam
Estimado Asier,



Amigo espero que te sirva esta función:



Public Function ConvertDataReaderToDataSet(ByVal reader As SqlDataReader) As
DataSet

Dim dataSet As DataSet = New DataSet()

Dim schemaTable As DataTable = reader.GetSchemaTable()

Dim dataTable As DataTable = New DataTable()

Dim intCounter As Integer

For intCounter = 0 To schemaTable.Rows.Count - 1

Dim dataRow As DataRow = schemaTable.Rows(intCounter)

Dim columnName As String = CType(dataRow("ColumnName"), String)

Dim column As DataColumn = New DataColumn(columnName, _

CType(dataRow("DataType"), Type))

dataTable.Columns.Add(column)

Next

dataSet.Tables.Add(dataTable)

While reader.Read()

Dim dataRow As DataRow = dataTable.NewRow()

For intCounter = 0 To reader.FieldCount - 1

dataRow(intCounter) = reader.GetValue(intCounter)

Next

dataTable.Rows.Add(dataRow)

End While

Return dataSet

End Function



Acuerdate de importer: Imports System.Data.SqlClient


Saludos cordiales,
Ángel Ruiz
[MS MVP - VB .NET]
Caracas - Venezuela

"El conocimiento es un bien, que crece a medida que se comparte"



NOTA. Por favor, las preguntas y comentarios en los grupos, así nos
beneficiamos todos.



"Asier" wrote in message
news:
Hola grupo,

¿Como puedo pasar el contenido de un DataReader a un DataSet?

Gracias



Preguntas similares