Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET DataReader values

Tags:

asp.net

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.

like image 554
w0051977 Avatar asked Dec 11 '11 12:12

w0051977


3 Answers

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.

like image 162
Shadow Wizard Hates Omicron Avatar answered Sep 22 '22 21:09

Shadow Wizard Hates Omicron


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

like image 20
Elias Hossain Avatar answered Sep 21 '22 21:09

Elias Hossain


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

like image 43
Nitesh Avatar answered Sep 20 '22 21:09

Nitesh