How can I see what's in a collection during debugging?

P

pantichd

<I also posted this on microsoft.public.vsnet.debugging 'cuz I didn't know
which was more appropriate or would get quickest response>


Hello,

Can someone tell me how I can view the contents of a collection when in
debug mode?

For example, I working with a dataset and when the app stops at a breakpoint
I'd like to see what is actually in the Tables collection of the dataset. I
add a watch on my dataset variable and expand the Tables object. It just
keeps showing me the following: Count, IsReadOnly, Is Synchronized, Item and
SyncRoot. Expand SyncRoot and you're at the beginning of a big old
recursion.

So if I want to see what's in row x of table y for example, I have to create
a variable in my code representing that row in that table and add a watch
for THAT variable. I have to believe that there is an easier, more dynamic,
way for me to inspect the content of this during debugging.

Any help would be greatly appreciated.

David.
 
P

Peter Rilling

Remember, collections are not the items themselves, they contain the items.
The Item property is actually what contains the values. Now, the debugger
is not good at listing items in the Item property so what you may have to do
is use an indexer to get at the data (assuming you are using C#). For
example, you would have to do myTbl[0] to see the properties, from there you
can access the rows, and so on.
 
P

pantichd

Peter,

First of all, thanks for responding.

I'm fairly new to .net (been doing Java for awhile) but I think I have a
pretty good handle on what collections are. : )

The situation I'm describing is something I've been able to do in other
tools.

It sounds like you're telling me that I really DO need to create a local
variable in my code to represent a specific table in the Tables collection
of a dataset.

I tried that and when I do a watch on that in the debugger I see that there
is an item called rows and another called rowCollection. When I expand those
I get in the recursion again.

The more I look at this the more I think I'm gonna have to define a local
variable to represent a specific row in a specific table. That seems very
inefficient. Please tell me there is a better way!

Thanks!

PS- I'm using VisualBasic.net
 
G

Guest

If you drill down into the dataset you will find tables. Drill down into it
and you will find columns and rows. Each of these has an items that you can
look at.
Kal

pantichd said:
Peter,

First of all, thanks for responding.

I'm fairly new to .net (been doing Java for awhile) but I think I have a
pretty good handle on what collections are. : )

The situation I'm describing is something I've been able to do in other
tools.

It sounds like you're telling me that I really DO need to create a local
variable in my code to represent a specific table in the Tables collection
of a dataset.

I tried that and when I do a watch on that in the debugger I see that there
is an item called rows and another called rowCollection. When I expand those
I get in the recursion again.

The more I look at this the more I think I'm gonna have to define a local
variable to represent a specific row in a specific table. That seems very
inefficient. Please tell me there is a better way!

Thanks!

PS- I'm using VisualBasic.net

Peter Rilling said:
Remember, collections are not the items themselves, they contain the items.
The Item property is actually what contains the values. Now, the debugger
is not good at listing items in the Item property so what you may have to do
is use an indexer to get at the data (assuming you are using C#). For
example, you would have to do myTbl[0] to see the properties, from there you
can access the rows, and so on.
 
P

Pedja

Hello,

Can someone tell me how I can view the contents of a collection when in
debug mode?

Hi David.

I usually use Command Window for that purpose. It is accessible when
the application is stopped (let's say after it hit the breakpoint).
You can type something like:

?myDataset.Tables(1).Rows(5).ItemArray

or

?myDataset.Tables(1).Rows(5)("ColumnName")

You can also use the Watch Window. Declare the watch variable as:

myDataset.Tables(1).Rows(5).ItemArray

I prefer Command Window since you'll have the help of IntelliSense
there.

Hope this helps.
- Pedja.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top