locked
DataRow from SqlDataReader RRS feed

  • Question

  • Hi Guys,

    Is it possible to use SqlDataReader in DataRow?

    I needed to get the row from a query using SqlDataReader and put it in a DataRow.

    Can you help me Guys!

    Dim cmd As SqlCommand = Nothing
    Dim drData As SqlDataReader = Nothing

    cmd = New SqlCommand(sSQL, cnSQL)
    drData = cmd.ExecuteReader()

    Dim rowRetVal() As DataRow

    DataRow(0) =  drData?????

    Thanks in advance.

    Thursday, August 8, 2013 3:40 AM

Answers

  • No you can't do it. You would have to map data out of the datareader by column ordinal position and map it to a datarow column name or ordinal position using an index and do it column by column.

    Most developers when using a datareader and returning data out of a datareader  would use a custom object and populate the custom object with data from the datareader. A single custom object would be returned, or a collection of custom objects would be returned in a List<T>.  No datatable with a row would even be involved with this.

    Thursday, August 8, 2013 4:44 AM

All replies

  • No you can't do it. You would have to map data out of the datareader by column ordinal position and map it to a datarow column name or ordinal position using an index and do it column by column.

    Most developers when using a datareader and returning data out of a datareader  would use a custom object and populate the custom object with data from the datareader. A single custom object would be returned, or a collection of custom objects would be returned in a List<T>.  No datatable with a row would even be involved with this.

    Thursday, August 8, 2013 4:44 AM
  • Okay. Noted. Thanks.
    Thursday, August 8, 2013 5:23 AM