LINQ - How to get numbers from range that not present in DataTable column?

Asked By Rahim Huseyn on 23-Sep-12 08:14 AM
Hello Friends?
I have a DataTable with Id(int) column(and NameField);
The Id values are:
2  John
3  John2
5  John3
7  No John
9  ...
10  ... 
11  ...

My range is [1, 20]
I want to get values 1, 4, 6, 8, 12, 13, 14, 15, 16, 17, 18, 19, 20 (that are not included to Id values Set)

How to organise Linq query?(C#...)
Thank you!
kianu rieves replied to Rahim Huseyn on 24-Sep-12 01:16 AM
You have a DataView on this table with a sort order set, you can use the DataView.Find() method and it returns a row index.
http://www.dapfor.com/en/net-suite/net-grid/tutorial/event-driven-model
Rahim Huseyn replied to kianu rieves on 24-Sep-12 08:42 AM
I used DataView as you said, thank you very much.
The whole solution is:
DataView dv30 = new DataView(dtMain);

dv30.RowFilter =

"NumField > " + ib.ToString() + " and NumField <= " + textBox1.Text + "9999";

dv30.Sort = "NumField";

int imax = (Int32)dv30[dv30.Count-1]["NumField"];

DataTable newDataTable = dv30.ToTable(true, new string[1] { "NumField" });



int[] masPap = new int[newDataTable.Rows.Count];

int i = -1;

foreach (DataRow item in newDataTable.Rows)

{

masPap[++i] = (

Int32)item["NumField"];

}

StringBuilder sb = new StringBuilder("");

IEnumerable<int> squares = Enumerable.Range(ib+1, imax - ib).Except(masPap);

foreach (int num in squares)

{

sb.Append(num+

" ");

}