Comparing for Columns
-
Hi everybody, I have DataSet which is filled by a database table called "schedule". And I want to compare the values of specific columns that are found in different rows, is possible? If it is, how? Thank you.
-
Hi everybody, I have DataSet which is filled by a database table called "schedule". And I want to compare the values of specific columns that are found in different rows, is possible? If it is, how? Thank you.
The rows are indexed entries, so you can refer to them by their position. Suppose, for instance, that you want to compare items in the current row and the next row, the following code will do:
DataTable tbl = myDataSet[0];
for (int i = 0; i < tbl.Rows.Count - 1; i++)
{
if (tbl.Rows[i]["myColumn"] == tbl.Rows[i+1]["myColumn"])
{
// It's a match
}
}"WPF has many lovers. It's a veritable porn star!" - Josh Smith
As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
-
Hi everybody, I have DataSet which is filled by a database table called "schedule". And I want to compare the values of specific columns that are found in different rows, is possible? If it is, how? Thank you.
Apart from what has been replied, you can also use the DataTable.Select method. You can specify the column value there and all the rows having that value will be returned. Depends on the scenario, which approach you should go for.
It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD