Reputation: 18973
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.
Upvotes: 0
Views: 454
Reputation: 28530
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]);
}
}
Upvotes: 1
Reputation: 7117
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
Upvotes: 2