none
datareader with two tables RRS feed

  • Question

  • hi friends,

    is it possible for a single datareader to read a data from two tables or two sp's.

     

    Friday, November 16, 2007 7:03 AM

Answers

  • Yes, it is possible if provider supports multiple SQL statements in one batch. With SQL Server you can definitely do this. Assume you have next batch of statements

     

    SELECT ... FROM Table 1...;

    SELECT ... FROM Table 2...

     

    In this case when you open reader executing this batch of statements, provider opens reader for the first SQL statement and you navigate forward into it until you reach the end. If you want to switch to second reader, you call NextResult method of the reader, but you cannot go back to the first one after you moved to the next result

     

    Friday, November 16, 2007 11:28 AM
    Moderator

All replies

  • Yes, it is possible if provider supports multiple SQL statements in one batch. With SQL Server you can definitely do this. Assume you have next batch of statements

     

    SELECT ... FROM Table 1...;

    SELECT ... FROM Table 2...

     

    In this case when you open reader executing this batch of statements, provider opens reader for the first SQL statement and you navigate forward into it until you reach the end. If you want to switch to second reader, you call NextResult method of the reader, but you cannot go back to the first one after you moved to the next result

     

    Friday, November 16, 2007 11:28 AM
    Moderator
  • thanks for the replay, i got the solution through you

     

    Monday, November 19, 2007 6:44 AM