I want to filter my DataTable based on certain filtering conditions.
Here’s my code:
parameters = objPatientBizProcessing.GetFilterParameters(campusSelection, statusSelection);
filterOption3 = "pat_status = '" + parameters[1] + "'";
foreach (DataRow dr in dt.Rows)
{
dataRows = dt.Select(filterOption3, "id");
foreach (DataRow dr1 in dataRows)
{
dt1.Rows.Add(dr1);
}
}
I have a total of 10 records in my dt, and based on filterOption3 I’m filtering the results to dt1.
Error:
This row belongs to another Table
I’m not “allowed” to use a DataView.
Is there a solution?
You can only add rows to a
DataTablethat has been created usingdt.NewRow()on that Table. You need to usedt.ImportRow(row).Can you not use the
dataRowscollection from the select directly instead?