2012-05-22 2 views
3

이 저장 프로 시저 'get2Rows'는 2 행을 반환하고, 첫 번째 행을 가져와 열 값을 얻은 다음 두 번째 행을 가져와 열 값을 가져 오려고합니다. 어떻게 반복해야합니까? 당신이 그들을 통해 반복되기 때문에결과 집합 반복하기 .Net

using (System.Data.Common.DbCommand dbCommand = DataAccess.Instance().Database.GetStoredProcCommand("get2Rows")) 
{  
    using (IDataReader reader = DataAccess.Instance().Database.ExecuteReader(dbCommand)) 
    { 
     while (reader.Read())//here i want to get the 1st row 
     { 
      //here i want to get the columns of the 1st row.... 
     }        
    };       
} 

답변

1
while (reader.Read())//here i want to get the 1st row 
{ 
    //here i want to get the columns of the 1st row.... 
    int firstColumn = Convert.ToInt32(dr[0]["intColumn"].ToString()); 
    string secondColumn = dr[0]["stringColumn"].ToString(); 
    // etc. 
} 

당신은 두 행을 받고 있습니다. 어떻게 컬렉션에 보관할 것인가는 당신에게 달려 있습니다.

상세 정보 : http://www.csharp-station.com/Tutorial/AdoDotNet/lesson04

내 조언은 그게 작동 방식이기 때문에 당신은 DataReader를 사용하는 경우 한 번에 하나의 행에서 작동하는 것입니다. 모든 행을 메모리에 저장하려면 DataSet을 대신 사용해야합니다.