0

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

Abhilash VG
  • 15
  • 1
  • 5

2 Answers2

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.