7

Is there a way of viewing the values inside a DataReader in Visual Studio. Please note that I am referring the watch window when debugging. For example, if there are two fields inside the datareader i.e. ID and Name, is there a way to view the values? When I hover above the DataReader, it just tells me what type of object it is i.e. a datareader.

3 Answers 3

4

You can view both columns and data in the reader as below:

To view columns: Quick watch to the reader > Result View > [0], 1...[expand any index] > Non-Public members > _schemainfo > [0], 1...[expand any index], this will show you column name and data type.

To view data: Quick watch to the reader > Result View > [0], 1...[expand any index] > Non-Public members > _values > [0], 1...[expand any index], this will show you data present at the columns.

Edit: Column Information View ColumnView

Data View for columns DataView

Update: data also can see as below way:

if (reader.HasRows)
{
    while (reader.Read())
    {
        int Id = Convert.ToInt32(reader["ID"]);
        string Name = Convert.ToString(reader["Name"]);
    }
}

Thanks

Sign up to request clarification or add additional context in comments.

6 Comments

There is no results view under the DataReader. There is: depth,fieldcount,hasrows,isclosed,recordsaffected and visible field count.
Which .NET Framework version are you using, I'm using 4.0, so far it is also available from 3.0, thanks for your time, thanks for your time.
I am trying the view the values inside the datareader using the watch window (without having to qrite more code). I am using version 3.5. Thanks.
I have opened QuickWatch and added the DataReader, however there is no option for Static Members, so I cannot expand it (as in your screen shot). I am using Visual Studio Professional Edition 2008.
Oh! I'm using Visual Studio 2010, would you please try with that, thanks for your time.
|
3

You can't do that due to the nature of DataReader: it does not store the actual data, just some sort of "pointer" to the database.

To have the Reader be filled with data, you must call its Read() method - this will populate the object with the values of the next record, if available then return true otherwise it will return false and the data won't be available.

In the watch window of Visual Studio you should be able to dynamically execute that Read() method - just type reader.Read() and see the result - then to read the current values just write reader[0] and reader[1] in the watch window.

Anyhow, none of this is possible just from the tooltip, only in the special watch window.

Comments

2

You can type reader["ID"] and reader["Name"] to view the value in watch window.

2 Comments

When I try this it says: cannot convert id to SQLDataReader.
I am trying to view the values in the watch window, therefore without writing code. Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.