访问datatable的单元格值 [英] Access cell value of datatable
本文介绍了访问datatable的单元格值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
任何人都可以帮助我如何访问第4列中第一个单元格的示例值?
Can anyone help me how to access for example value of first cell in 4th column?
a b c d
1 2 3 5
g n m l
例如,如何访问价值d,如果这将datatable?
for example, how to access to value d, if that would be datatable?
谢谢。
推荐答案
到单元格值:
object field = d.Rows[0][3]
或
object field = d.Rows[0].ItemArray[3]
应该这样做
如果您需要强类型引用(在您的情况下为字符串),则可以使用 DataRowExtensions.Field 扩展方法:
If you need a strongly typed reference (string in your case) you can use the DataRowExtensions.Field extension method:
string field = d.Rows[0].Field<string>(3);
(确保System.Data在这种情况下在命名空间中列出)
(make sure System.Data is in listed in the namespaces in this case)
索引为0,所以我们首先访问第一行(0),然后访问此行(3)中的第4列
Indexes are 0 based so we first access the first row (0) and then the 4th column in this row (3)
这篇关于访问datatable的单元格值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文