开发者

Filter DataTable

I want to filter my DataTable based on certain filtering conditions.

Here's my code:

开发者_Python百科    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 DataTable that has been created using dt.NewRow() on that Table. You need to use dt.ImportRow(row).

Can you not use the dataRows collection from the select directly instead?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜