If i understand you well, you want to get index. The best way to achieve that, if your data model does not have unique key, is to add
AutoIncrement field[
^] to the
DataTable
. See:
Creating AutoIncrement Columns[
^]
DataTable dt = new DataTable();
DataColumn dc = new DataColumn("index", typeof(Int32));
dc.AutoIncrement = true;
dc.AutoIncrementSeed = 1;
dc.AutoIncrementStep = 1;
dt.Columns.Add(dc);
dc = new DataColumn("Breakpoint", typeof(Int32));
dt.Columns.Add(dc);
dc = new DataColumn("rate", typeof(double));
dt.Columns.Add(dc);
dt.Rows.Add(null, 10000,5.5);
dt.Rows.Add(null, 20000,4);
dt.Rows.Add(null, 35000,3);
dt.Rows.Add(null, 50000, 2.5);
dt.Rows.Add(null, 100000, 1);
Result:
index Breakpoint rate
1 10000 5,5
2 20000 4
3 35000 3
4 50000 2,5
5 100000 1
Now, you can loop through the records (no matter of drirection) and the index is always the same ;)
Check this:
var qry = dt.AsEnumerable()
.Where(r => r.Field<int>("Breakpoint")>30000);
foreach(var row in qry)
{
Console.WriteLine("{0}: {1}", row.Field<int>("index"), row.Field<int>("Breakpoint"));
}