idatareader?

  • Thread starter Thread starter js
  • Start date Start date
J

js

Hi, I want to debug the return idatareader, how to print out some fields
value? many thanks.
 
Unforunately, there isn't a clean cut way to see the values in the debugger.

i'm typing this from memory, but should get you started ..........

it probably has some syntax errors, but should be correctable.


public void ShowDataReaderValues( IDataReader idr)
{
bool keepChecking = true;
int counter = 0;

if (null != idr)
{
while (idr.Read())
{
while keepChecking = true;


{


if (!idr.IsDBNull(counter))
{
object o = idr.GetValue(counter++);
Console.WriteLine (o.ToString());
}

if (counter>idr.Depth)
{
keepChecking=false;
}

}



}

}
 
thanks sloan...

sloan said:
Unforunately, there isn't a clean cut way to see the values in the
debugger.

i'm typing this from memory, but should get you started ..........

it probably has some syntax errors, but should be correctable.


public void ShowDataReaderValues( IDataReader idr)
{
bool keepChecking = true;
int counter = 0;

if (null != idr)
{
while (idr.Read())
{
while keepChecking = true;


{


if (!idr.IsDBNull(counter))
{
object o = idr.GetValue(counter++);
Console.WriteLine (o.ToString());
}

if (counter>idr.Depth)
{
keepChecking=false;
}

}



}

}
 
Since I put the wrong Property.. I fixed it.. (and since you were nice
enough to say thank you)



Here is a version that works "out of the box".

(Don't forget to .Close() those datareaders as soon as you're done with them
!! )





public void ShowDataReaderValues( IDataReader idr)

{

bool keepChecking = true;

int counter = 0;

bool resultSetExists = true;//assume at least 1 result set



if (null != idr)

{

while (resultSetExists)

{

while (idr.Read())

{

keepChecking = true;//reset

counter=0;//reset

Console.WriteLine ("------------------------------");

while (keepChecking == true)

{

if (!idr.IsDBNull(counter))

{

object o = idr.GetValue(counter++);

Console.WriteLine (o.ToString());

}

if ( counter>=idr.FieldCount )

{

keepChecking=false;

}

}

}



resultSetExists = idr.NextResult(); // this will figure out if there is
another result set



}

}

}
 

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

Back
Top