2009-09-09 8 views

答えて

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

これにより、1つの列を参照することができる方法です。列の最初から最後までの意味は?

各列の値を格納するコントロールは何ですか?

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

データテーブルのRowsプロパティは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のを使用していないので、私はこの方法に寄りかかっこだわっています。

関連する問題