2009-09-09 5 views

답변

1
Tabla.Rows[0]["mycolumnName"] 

이 단일 열을 참조 할 수있는 방법입니다. 처음부터 끝까지 열의 의미는 무엇입니까?

각 열의 값을 저장하려는 컨트롤은 무엇입니까?

1

일반적으로 데이터 집합의 테이블 컬렉션에 액세스 한 다음 테이블의 행 컬렉션에 액세스합니다. 이와 같이 :

myDataSet.Tables[0] // you can also use the name of the table, instead of an integer 

myTable.Rows[ n ] // this will give you the nth row in the table 

myRow[ n ]   // this will give you the nth column in the row, you can use the 
        // name of the column instead of an integer 

이렇게하면 데이터 집합의 모든 테이블에서 모든 행의 모든 ​​열을 반복합니다.

foreach(DataTable curTable in myDataSet.Tables) 
{ 
    foreach(DataRow curRow in curTable.Rows) 
    { 
      foreach(DataColumn curCol in Table.Columns) 
      { 
       object item = curRow[ curCol ]; 
      } 
    } 
} 
1

데이터 테이블의 행 속성은 IEnumerable입니다. LINQ는 여기에가는 더 좋은 방법이지만 여기서는 foreach 루프를 사용하여 수행하는 방법입니다 (질문을 올바르게 이해하는 경우).

처음부터 끝까지 열을 가져오고 싶습니다. textboxes.text.

foreach(System.DataRow dr in Tabla.Rows)//iterate rows 
{ 
    foreach(System.DataColumn dc in Tabla.Columns) //iterate columns per row 
    { 
     textboxes.text = dr[dc].ToString(); //get object value at row,column 
    } 
} 

LINQ는 람다 추천하고 좋지 않을까하지만, 슬프게도, 우리는 아직 여기 3.x를 사용하지 않습니다 그래서이 방법에 기대어 붙어있어.