title: How To Populate A Gridview Dynamically Using Multiple Queries
body: <p>I have two tables, <code>UserInfo</code> (PrimaryKey= UID) and <code>Relationships</code> (PrimaryKey= RID, ForeignKey= UID).
  Relationships data example:</p>
  
  <pre>
  
  | UID | RID |
  
  |  2  |  3  |
  
  |  3  |  4  |
  
  </pre>
  
  <p>Now, after executing an sql query, that performs some sorting on Relationships table like:</p>
  
  <pre><code>"select RID from Relationships where UID= "value"
  UNION select UID from Relationships where RID= "value " 
  </code></pre>
  
  <p>if the value = 3, i get the integer values such 2 , 4 (which means 3 has relationships with 2 and 4)</p>
  
  <p>if value = 4, result = 3 (4 only has relationship with 3)</p>
  
  <p>etc these resulting values are PrimaryKey values of the <code>UserInfo</code> table.</p>
  
  <p>What i want to do is to fetch the Information of Users having the <code>UID</code> = 23,25,34 (These values are the result of first SQL query, so the number of values and values changes every time according to the values passed to first SQL query)
  and bind it with an asp Gridview.</p>
  
  <p>for this, i think i'll have to execute multiple sql queries like</p>
  
  <pre><code>select * from UserInfo where UID= 2
  
  select * from UserInfo where UID= 4
  </code></pre>
  
  <p>etc</p>
  
  <p>using a loop.</p>
  
  <p>What i think i should do is to loop through the results of first sql query, execute the second query according to it and save the resulting recordset in another table or any sort of datasource, which is finally bind to the gridview... but i don't know how to implement it..</p>
  
  <p>this is my first question in StackOverflow.. i'll try my best to further clarrify the problem if necessory..</p>
  
  <p>any help would be greatly appreciatable..! :)</p>