我如何从我的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的又那么我坚持靠着这个方法。