Modify rows added into dataset

♀尐吖头ヾ 提交于 2020-01-06 13:56:02

问题


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 possible?

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.


回答1:


C# Version (Please accept f0x's answer if this is the method you're looking for):

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]);
    }
}



回答2:


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


来源:https://stackoverflow.com/questions/6908124/modify-rows-added-into-dataset

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!