Access cell value of datatable
Czy ktoś może mi pomóc jak uzyskać dostęp np. do wartości pierwszej komórki w 4 kolumnie?
a b c d
1 2 3 5
g n m l
Na przykład, jak uzyskać dostęp do wartości d, jeśli byłoby to możliwe?
Dzięki. 66
6 answers
Jeśli potrzebujesz słabego odniesienia do wartości komórki:
object field = d.Rows[0][3]
Lub
object field = d.Rows[0].ItemArray[3]
Should do it
Jeśli potrzebujesz silnie wpisanego referencji (string w Twoim przypadku), możesz użyć DataRowExtensions.Pole metoda rozszerzenia:
string field = d.Rows[0].Field<string>(3);
(Upewnij się System.Dane są wymienione w przestrzeniach nazw w tym przypadku)
Indeksy są oparte na 0, więc najpierw uzyskujemy dostęp do pierwszego wiersza (0), a następnie czwartej kolumny w tym wierszu (3)
108
Author: vc 74,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-10-28 13:29:39
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-10-28 13:29:39
string abc= dt.Rows[0]["column name"].ToString();
60
Author: ashok luhach,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-06-10 11:20:00
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-06-10 11:20:00
Możesz również spróbować (pierwsza komórka w 4 kolumnie):
dt.Rows[0][3]
9
Author: FrenkyB,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-01-08 14:50:23
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-01-08 14:50:23
foreach(DataRow row in dt.Rows)
{
string value = row[3].ToString();
}
8
Author: gabsferreira,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-01-26 17:15:27
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-01-26 17:15:27
Dane d są w wierszu 0 i kolumnie 3 dla wartości d:
DataTable table;
String d = (String)table.Rows[0][3];
5
Author: athena,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-06-24 13:42:48
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-06-24 13:42:48
public V[] getV(DataTable dtCloned)
{
V[] objV = new V[dtCloned.Rows.Count];
MyClasses mc = new MyClasses();
int i = 0;
int intError = 0;
foreach (DataRow dr in dtCloned.Rows)
{
try
{
V vs = new V();
vs.R = int.Parse(mc.ReplaceChar(dr["r"].ToString()).Trim());
vs.S = Int64.Parse(mc.ReplaceChar(dr["s"].ToString()).Trim());
objV[i] = vs;
i++;
}
catch (Exception ex)
{
//
DataRow row = dtError.NewRow();
row["r"] = dr["r"].ToString();
row["s"] = dr["s"].ToString();
dtError.Rows.Add(row);
intError++;
}
}
return vs;
}
0
Author: Ata Hoseini,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-06-20 04:26:51
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-06-20 04:26:51