SqlDataReader problem

Ask a Question related to ASP.NET General, Design and Development.

  1. #1

    Default SqlDataReader problem

    Hello,

    With my SqlDataReader I select 2 records.

    Here is a little bit of my code:
    SqlDataReader dr = documents.GetDocuments(ModuleId);

    // 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!


    Arjen Guest

  2. Similar Questions and Discussions

    1. Is there a way to convert a sqldatareader to a dataview?
      The sqldatareader is very fast but the dataview is very versatile. I need the features of the dataview and the speed of the datareader.
    2. Cross-Site Scripting & sqlDataReader
      I am using sqlDataReader for Showing data from the Data base. But if the Data from sql is having tags like <script>alert()</script> then it shows an...
    3. Passing SqlDataReader thro a web service...
      Hi, I was trying to generate a c# proxy file which contained a web method that returned SqlDataReader but the wsdl http://localhost/etc etc said...
    4. DataGrid Custom Paging using SQLDataReader
      Hi Everyone, I am trying to implement a DataGrid that uses Custom paging, but the DataSource is a SQLDataReader, not a DataSet. I have seen...
    5. reading sqldatareader after conn.close()
      "Naveen K Kohli" <naveenkohli@hotmail.com> wrote in message news:<uDh3MJKQDHA.2476@TK2MSFTNGP10.phx.gbl>... Thanks. Can I do smt. like in code...
  3. #2

    Default 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@hotmail.com> wrote in message
    news:bg8uq7$eip$1@news4.tilbu1.nb.home.nl...
    > Hello,
    >
    > With my SqlDataReader I select 2 records.
    >
    > Here is a little bit of my code:
    > SqlDataReader dr = documents.GetDocuments(ModuleId);
    >
    > // 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 Guest

  4. #3

    Default Re: SqlDataReader problem

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

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


    "Arjen" <boah123@hotmail.com> wrote in message
    news:bg8uq7$eip$1@news4.tilbu1.nb.home.nl...
    > Hello,
    >
    > With my SqlDataReader I select 2 records.
    >
    > Here is a little bit of my code:
    > SqlDataReader dr = documents.GetDocuments(ModuleId);
    >
    > // 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!
    >
    >

    MS News Guest

  5. #4

    Default Re: SqlDataReader problem

    Nope, I understand.



    "MS News" <sql_agentman@hotmail.com> schreef in bericht
    news:eKlxyNsVDHA.3088@tk2msftngp13.phx.gbl...
    > call dr.Read() again and not dr.NextResult()
    >
    > You don't have multiple Select in your Query??
    >
    >
    > "Arjen" <boah123@hotmail.com> wrote in message
    > news:bg8uq7$eip$1@news4.tilbu1.nb.home.nl...
    > > Hello,
    > >
    > > With my SqlDataReader I select 2 records.
    > >
    > > Here is a little bit of my code:
    > > SqlDataReader dr = documents.GetDocuments(ModuleId);
    > >
    > > // 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!
    > >
    > >
    >
    >

    Arjen Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139