21 September 2014

Iterate through a DataTable

You can iterate through a DataTable and create new one with comma separated values, something like this:

 Example :   
                            string result = string.Empty;
            DataTable dt=new DataTable;

             dt = obj.GetIDs();

List myIds = new List();

foreach(DataRow dr in dt.Rows)

{

   myIds.Add( Convert.ToString(dr["ID"]));

}

string result = string.Join(",", myIds);

 

No comments:

Post a Comment