Thursday, August 30, 2007

Search dataset/dataview using primary key

If you have a huge dataset, the performance of searching a record using dataset.Select won't be efficient. The best way to do this is to make primary key(s) of the dataset/dateview.

following line add two primary keys to the dataview
DataView dv = new DataView(dt,null,"pol_nbr,pol_sfx",DataViewRowState.CurrentRows);
then you can search a row by these keys


object[] keys = new object[2];
keys[0] = "0000"+p.Number;
keys[1] = p.Suffix;
DataRowView[] drv = dv.FindRows(keys);

No comments: