Hi i have to datatables - two columns in each table.
The first column in both is guid.
I need to compare the guids in these two tables.
And return one datatable witch contains the second columns from each table.
To combine data from two tables where the guid is equal.
(Note: it doesnt have to be datatables, could be string arrays or whatever really.)
This code below never returns isEq=true - anyone has some code that can do this ?
bool isEq;
foreach(DataRow r_row in dtRvtPfv.Rows)
{
foreach (DataColumn r_col in dtRvtPfv.Columns)
{
if (r_col.ColumnName == BuiltInParameter.IFC_GUID.ToString())
{
if (r_row[r_col] != null)
{
isEq = dtTeklaPfv.Select().ToList().Exists(row => row["GUID"].ToString() == r_row[r_col].ToString());
if (isEq)
{
TaskDialog.Show("Guid match", r_row[r_col].ToString());
}
}
}
}
}
Solved! Go to Solution.
Solved by jeremytammik. Go to Solution.
Dear Hd12310,
Happy New Year to you!
Sorry, I find both your question and your code hard to comprehend, so I cannot really answer it in this state.
Best regards,
Jeremy
Thanks for reply Jeremy.
Basically im trying to update elements based on their guid.
The elements have been exported to IFC - and sent to Tekla.
Tekla evaluates the elements and produce an status report for each element.
I have the Revit elements in one table and the tekla report in another table.
I need to copy the Tekla status from one dataTable to the other dataTable - by matching their guids like this:
DataTable1
guid status
287A628346 OK
387A628346 NOT_OK
DataTable2
guid ElementId
287A628346 Family1
387A628346 Family1
The goal is to compare and combine DataTable1 and DataTable2 - to get DataTable3
DateTable3
guid ElementId status
287A628346 Family1 OK
387A628346 Family1 NOT_OK
I realize its not really a core Revit API question so i will be digging into some MSDN forums for this as well.
Hi Hd12310,
Personally, I would create two generic .NET dictionaries keyed on the GUIDs.
Loop through one of the dictionaries, check whether the other dictionary has a corresponding entry.
If not, you are done. If yes, do your thing.
Cheers,
Jeremy
Thanks.
I ended up using the datatables directly and lopped through the rows.
Heres the working sample code if anyone is interrested.
From there on i could create a 3. datatable or just expand dtA with values from dtB.
string guid_a = ""; //in datatable dtA
string guid_b = ""; //in datatable dtB
foreach(DataRow a_row in dtA.Rows)
{
guid_a = (string)a_row["GUID"];
foreach(DataRow b_row in dtB.Rows)
{
guid_b = (string)b_row["GUID"];
if(guid_a.Equals(guid_b))
{
//we have a match
}
}
}
A more complicated solution, but with cleaner code would be using Linq instead or recursive loops:
http://msdn.microsoft.com/en-us/library/bb386943(v=vs.110).aspx
http://stackoverflow.com/questions/24020981/linq-query-multiple-datatables-in-dataset
Can't find what you're looking for? Ask the community or share your knowledge.