Can dataReader hold data from multiple tables ?

 Posted by Bharathi Cherukuri on 5/21/2012 | Category: ADO.NET Interview questions | Views: 3736 | Points: 40
Answer:

Data reader can hold data from multiple tables and datareader can hold more than one table.

Example:

string query="select * from employee; select * from student";

sqlcommand cmd=new sqlcommand(query, connection);
sqldatareader dr=cmd.executeReader();
if(dr.hasrows)
{
dr.read();
gridview1.DataSource=dr;
gridview1.Databind();
if(dr.nextresult)
{
gridview2.datasource=dr;
gridview2.databind();
}
}
dr.colse();
connection.close();


Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response