我如何从 table 中获取值并将其放入每个
How can I take values from a table and put it in a for each
我正在创建一个控制台应用程序来检查 table 中的用户是否有效。
这个想法是从用户 table 中获取 each 用户 alias/email 并将其放入 for-each 并将其与 AD 帐户详细信息进行比较并验证是否用户是否活跃..
我已经编写了检查 AD 的代码,但我不确定如何从 table 中获取 each 值并将其放入 for-each
这可以帮助你:
DataTable dt = GetTable();
for(int i = 0; i< dt.Rows.Count;i++)
for (int j = 0; j <dt.Columns.Count ; j++)
{
object o = dt.Rows[i].ItemArray[j];
//if you want to get the string
//string s = o = dt.Rows[i].ItemArray[j].ToString();
}
另见 this。
另一种方法是这样的:
foreach (DataRow row in dt.Rows)
{
var user = row["User"];
// ["User"] is the name of the column. Change it to your column name.
}
DataTable dt = yourTable;
string userName = string.empty;
foreach(DataRow row in dt.Rows)
{
userName = row["user_name"];
//Perform the comparison here
}
I wrote this code without IDE so there may be some syntax errors.
Let me know if it doesn't solve your problem.
我正在创建一个控制台应用程序来检查 table 中的用户是否有效。 这个想法是从用户 table 中获取 each 用户 alias/email 并将其放入 for-each 并将其与 AD 帐户详细信息进行比较并验证是否用户是否活跃.. 我已经编写了检查 AD 的代码,但我不确定如何从 table 中获取 each 值并将其放入 for-each
这可以帮助你:
DataTable dt = GetTable();
for(int i = 0; i< dt.Rows.Count;i++)
for (int j = 0; j <dt.Columns.Count ; j++)
{
object o = dt.Rows[i].ItemArray[j];
//if you want to get the string
//string s = o = dt.Rows[i].ItemArray[j].ToString();
}
另见 this。
另一种方法是这样的:
foreach (DataRow row in dt.Rows)
{
var user = row["User"];
// ["User"] is the name of the column. Change it to your column name.
}
DataTable dt = yourTable;
string userName = string.empty;
foreach(DataRow row in dt.Rows)
{
userName = row["user_name"];
//Perform the comparison here
}
I wrote this code without IDE so there may be some syntax errors. Let me know if it doesn't solve your problem.