Search code examples
c#.netasp.netvisual-studiodataset

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 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.


Solution

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