views:

58

answers:

1

i have used dictionary to collect the array of values

i have value in DataTable .

How to compare the values get from DataTable, whether dictionary key contains the name in DataTable. if DataTable has not that value,then remove that key name from dictionary.

My code:

DataTable dtcolumnsname = clsServiceManager.Instnce.Get_ColumnNames(ClsUserInfo.UserName, strTableName);
Dictionary<string,string> FinalDicColumnVal = new Dictionary<string,string>();

foreach (KeyValuePair<string, string> item in ColumnValues)
{
   if (dtcolumnsname.Columns.Contains(item.Key))
   {
       FinalDicColumnVal.Add(item.Key, item.Value);
   }
}

but this if (dtcolumnsname.Columns.Contains(item.Key)) is not get values of each datarow items in datatable.how to compare the dt row values with dictionary key names

+1  A: 

You may make list of values from DataTable, and then work with this list.

List<String> list = new List<string>();
foreach (DataRow row in dtcolumnsname.Rows)
{
    list.Add((string) row["ColumnName"]);
}
Pavel Belousov