DBCommandWrapper and IDispose

G

Guest

Just curious,

Data Access Application Block people:

Since DBCommandWrapper implements IDispose I use 'using' when working with
it. This is leading to a not too attractive loop structure when working with
DataReaders because I'm indented half way across the screen before actually
working with data. Q: Why does the DBCommandWrapper implement IDispose?:

try
{
using (DBCommandWrapper dbcw = ...)
{
using (IDataReader dr = ...)
{
...
}
}
}
 
N

Nicholas Paldino [.NET/C# MVP]

Richard,

It implements dispose because it holds a reference to an instance that
implements IDisposable, most likely.

You can always do this:

using (DBCommandWrapper dbcw = ...)
using (IDataReader dr = ...)
{
...

To cut down on the number of indentations.

Hope this helps.
 
D

David Browne

Richard said:
Just curious,

Data Access Application Block people:

Since DBCommandWrapper implements IDispose I use 'using' when working with
it. This is leading to a not too attractive loop structure when working
with
DataReaders because I'm indented half way across the screen before
actually
working with data. Q: Why does the DBCommandWrapper implement IDispose?:

Not sure if why. But you can clean up this scenario by stacking your using
statements just like you stack if statements.

You wouldn't write

if (foo)
{
//whatever
}
else
{
if (bar)
{
//whatever
}
else
{
//whatever
}
}



You can even add the whild loop to the stack:

using (DBCommandWrapper dbcw = ...)
using (IDataReader dr = ...)
while (dr.Read())
{
//whatever
}


David
 

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