SqlDataReader problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Arjen

    #1

    SqlDataReader problem

    Hello,

    With my SqlDataReader I select 2 records.

    Here is a little bit of my code:
    SqlDataReader dr = documents.GetDo cuments(ModuleI d);

    // Load first row into Datareader
    if (dr.Read()) {
    // Read it!
    }

    // Load second row into Datareader
    if (dr.NextResult( )) {
    // Read it!
    }

    dr.Close();

    The problem is that the second record dr.NextResult() doesn't work. But
    there are two records selected!!!

    Why is it not working?

    Thanks!


  • Marina

    #2
    Re: SqlDataReader problem

    If the 2 records are both as a result of one query, then you just need to
    call Read again to advance to the next row.

    If they are in different record sets, then you need to call Read after
    calling NextResult, to advance the next result set to the first row.

    "Arjen" <boah123@hotmai l.com> wrote in message
    news:bg8uq7$eip $1@news4.tilbu1 .nb.home.nl...[color=blue]
    > Hello,
    >
    > With my SqlDataReader I select 2 records.
    >
    > Here is a little bit of my code:
    > SqlDataReader dr = documents.GetDo cuments(ModuleI d);
    >
    > // Load first row into Datareader
    > if (dr.Read()) {
    > // Read it!
    > }
    >
    > // Load second row into Datareader
    > if (dr.NextResult( )) {
    > // Read it!
    > }
    >
    > dr.Close();
    >
    > The problem is that the second record dr.NextResult() doesn't work. But
    > there are two records selected!!!
    >
    > Why is it not working?
    >
    > Thanks!
    >
    >[/color]


    Comment

    • MS News

      #3
      Re: SqlDataReader problem

      call dr.Read() again and not dr.NextResult()

      You don't have multiple Select in your Query??


      "Arjen" <boah123@hotmai l.com> wrote in message
      news:bg8uq7$eip $1@news4.tilbu1 .nb.home.nl...[color=blue]
      > Hello,
      >
      > With my SqlDataReader I select 2 records.
      >
      > Here is a little bit of my code:
      > SqlDataReader dr = documents.GetDo cuments(ModuleI d);
      >
      > // Load first row into Datareader
      > if (dr.Read()) {
      > // Read it!
      > }
      >
      > // Load second row into Datareader
      > if (dr.NextResult( )) {
      > // Read it!
      > }
      >
      > dr.Close();
      >
      > The problem is that the second record dr.NextResult() doesn't work. But
      > there are two records selected!!!
      >
      > Why is it not working?
      >
      > Thanks!
      >
      >[/color]


      Comment

      • Arjen

        #4
        Re: SqlDataReader problem

        Nope, I understand.



        "MS News" <sql_agentman@h otmail.com> schreef in bericht
        news:eKlxyNsVDH A.3088@tk2msftn gp13.phx.gbl...[color=blue]
        > call dr.Read() again and not dr.NextResult()
        >
        > You don't have multiple Select in your Query??
        >
        >
        > "Arjen" <boah123@hotmai l.com> wrote in message
        > news:bg8uq7$eip $1@news4.tilbu1 .nb.home.nl...[color=green]
        > > Hello,
        > >
        > > With my SqlDataReader I select 2 records.
        > >
        > > Here is a little bit of my code:
        > > SqlDataReader dr = documents.GetDo cuments(ModuleI d);
        > >
        > > // Load first row into Datareader
        > > if (dr.Read()) {
        > > // Read it!
        > > }
        > >
        > > // Load second row into Datareader
        > > if (dr.NextResult( )) {
        > > // Read it!
        > > }
        > >
        > > dr.Close();
        > >
        > > The problem is that the second record dr.NextResult() doesn't work. But
        > > there are two records selected!!!
        > >
        > > Why is it not working?
        > >
        > > Thanks!
        > >
        > >[/color]
        >
        >[/color]


        Comment

        Working...