I'm a beginner with VS C# and am working on a WINFORM project I inherited. I need to find rows in tbl1 that don't exist in tbl2 and delete them. The joining column would be: tbl1==> "VistaFieldNumber" tbl2==> "FMFieldNumber"
I found some code in StackOverflow link Get what exists in one DataTable but not another using LINQ that I thought might work but it's using linq which I'm not familiar with and is throwing an exception that 'FMFieldNumber' does not belong to table 'sAttributes'. This is true. 'FMFieldNumber' belongs to 'tAttributes'. I don't understand why I'm getting the exception on line: DataTable result = rowsOnlyIntblsAttributes.CopyToDataTable();
These tables have the field numbers in common but it is a 1 to 1 relationship. The reason for the delete rows is due to a de-selection from treeview and the tables must have same number of rows to update gridview and underlying table.
What am I missing to solve this? OR is there some other code that would solve?
else if (dsVX130.Tables["tAttributes"].Rows.Count > 0)
{
//synce sAttributes with tAttributes
var rowsOnlyIntblsAttributes = tblsAttributes.AsEnumerable().Where(r => !tbltAttributes.AsEnumerable()
//make sure there aren't any matching names in dt2
.Any(r2 => r["FMFieldNumber"].ToString().Trim().ToLower() == r2["VistaFieldNumber"].ToString().Trim().ToLower() ));
DataTable result = rowsOnlyIntblsAttributes.CopyToDataTable();
//delete rows then applyAttributes();
//applyAttributes();
} comparable syntax for C# WINFORMS? If not how can this be done?