I was creating a console application to check whether the users in a table are valid or not. The idea is to take each user alias/email from a user table and put it in a for-each and compare it with the AD Account details and verify whether the user is active or not.. I have written the code to check in AD but I am not sure how can I take each values from a table and place it in a for-each
Asked
Active
Viewed 65 times
0
-
What have you done so far? – Mehdi Dehghani Jan 23 '20 at 06:55
-
just added the code to check AD.. I have confused with the implementation – Abhilash VG Jan 23 '20 at 06:59
-
I'm sorry, I can see any change, did you know how to edit your post? – Mehdi Dehghani Jan 23 '20 at 07:01
2 Answers
1
This could help you out:
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();
}
Also see this.
Another way around would be something like this:
foreach (DataRow row in dt.Rows)
{
var user = row["User"];
// ["User"] is the name of the column. Change it to your column name.
}

Dave
- 50
- 1
- 7
1
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.

Ankit Sharma
- 69
- 2