开发者

Modify rows added into dataset

I have a dataaset1 which contains 17-20 rows. Now i have another dataset as dataset2, containing 4-5 rows. the rows of dataset 2 should be added into dataset1, which then should be binded to grid again (containing 22-25 rows in total).

How is that pos开发者_如何学Gosible?

Also, the dataset 2 rows have to be added based on some condition of dataset1 column. Say if column 1 is 'Y', then the dataset 2 rows should be added.


Possibly something like this - vb.net code but you should be fine:

'dataSet1 populated
'dataSet2 populated

        If dataset1.Tables(0).Rows(0)(0) = "Y" Then ' first row, first column check -  as example
            For i As Integer = 0 To dataset2.Tables(0).Rows.Count - 1
                dataset1.Tables(0).ImportRow(dataset2.Tables(0).Rows(i))
            Next
        End If

'Bind dataset1 to grid


C# Version:

UPDATED to address error above - use ImportRow

if (dataset1.Tables[0].Rows[0][0].ToString() == "Y")
{
    for (int i = 0; i < dataset2.Tables[0].Rows.Count - 1; i++)
    {
        dataset1.Tables[0].ImportRow(dataset2.Tables[0].Rows[i]);
    }
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜