【发布时间】:2020-07-25 07:34:40
【问题描述】:
我正在尝试从 DataTable 的特定列中的 DataRow 获取值。根据调试器,它应该返回类似“abc12345”的值,而是返回“ListViewSubItem: {abc12345}”。这是为什么呢?
foreach (DataRow row in itemsTable.Rows)
{
// the required data is in the first column of the DataTable
// both of the following have been tried:
string myValue = row[0].ToString();
string myValue = row.Field<string>(0);
}
【问题讨论】:
-
你是如何定义列的?您将列类型转换为字符串,因此根据表中的列定义,您将获得不同的响应。
-
@jdweng 就是这样!定义列时忘记设置类型了。