I have use dataTable and load the Idatareader and after this create the datareader ,
there after i am easily used this function with multiple loop.
public static IDataReader GetDataReader(DbConnection myConnection, string strQry)
{
IDataReader ObjmyReader0 = null;
IDataReader ObjmyReader = null;
var dt = new DataTable();
string RetVal = string.Empty;
DbCommand myCommand = null;
myCommand = (DbCommand)myConnection.CreateCommand();
myCommand.CommandText = strQry;
if (myConnection.State == ConnectionState.Closed || myConnection.State == ConnectionState.Broken) {
myConnection.Open();
}
try
{
if (ObjmyReader != null)
{
if (ObjmyReader.IsClosed == false)
{
ObjmyReader.Close();
}
}
ObjmyReader = (IDataReader)myCommand.ExecuteReader(System.Data.CommandBehavior.CloseConnection);
dt.Load(ObjmyReader);
}
catch (Exception rdExc)
{
if ((ObjmyReader != null) && (ObjmyReader.IsClosed == false))
{
ObjmyReader.Close();
ObjmyReader = (IDataReader)myCommand.ExecuteReader();
}
}
finally
{
myCommand.Dispose();
ObjmyReader0 = ObjmyReader;
}
return dt.CreateDataReader();
ObjmyReader0.Dispose();
}