我如何從我的datable獲取信息?從我加載的DataTable獲取信息
我只想從列表開始到結束,並將它們加載到textboxes.text。
ClienteHolder.IDCliente = Tabla.Rows[]?????
我如何從我的datable獲取信息?從我加載的DataTable獲取信息
我只想從列表開始到結束,並將它們加載到textboxes.text。
ClienteHolder.IDCliente = Tabla.Rows[]?????
Tabla.Rows[0]["mycolumnName"]
這是你可以參考一列。從開始到結束,專欄的含義是什麼?
您希望將每個列的值存儲在哪些控件中?
一般來說,您訪問數據集的表集合,然後訪問表的集合。像這樣:
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 ];
}
}
}
datatable的行屬性是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是LAMDA一樣,真棒,但很可惜,我們沒有在這裏使用3.x的又那麼我堅持靠着這個方法。