CtExcelData [datatable1]
DESIGNATION STATUS
------------------------------------------
ASSISTANT MANAGER - TRAINING ACTIVE
ASSISTANT MANAGER - TRAINING ACTIVE
ADMIN ASSISTANT ACTIVE
名称 [数据表2]
DESIG_ID DESIG_NAME
------------------------------------------
10 ASSISTANT MANAGER - TRAINING
20 ADMIN ASSISTANT
我想使用 lambda 表达式在 datatable2 中的指定名称与 2 个数据表之间完全匹配,则我想在 datatable2 中用指定 ID 替换 datatable1DESIGNATION
文本。
2 个表中将有多行。
//CtExcelData datatable imported from excel compared with Designation datatable fetched from db. Updated excel datatable with id from db table matching the designationname
foreach (DataRow row in CtExcelData.Rows){
DataRow desigRowsToUpdate = DS.Tables["Designation"].AsEnumerable().FirstOrDefault(r => r.Field<string>("Desig_Name").ToUpper().Trim() == row.Field<string>("DESIGNATION").ToUpper().Trim());
if (desigRowsToUpdate != null)
{
row.SetField("DESIGNATION", desigRowsToUpdate.Field<decimal>("Desig_Id"));}
}