问题
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