Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.Net Add Index to Datatable (dataset)

Tags:

c#

vb.net

dataset

Is there a way to add an index to a datatable in .Net?

I have a datatable holding about 1,100 rows and the datatable.select statement seems a bit slow for an in-memory operation.

like image 358
Jeff Avatar asked May 03 '16 23:05

Jeff


1 Answers

table.PrimaryKey = new DataColumn[]{table.Columns["column1"],table.Columns["column2"]}

when searching

table.Rows.Find(New Object[]{<value in column1>, <value in column2>})

This will return a datarow. Also the Primary key values must be unique, otherwise an exception will be thrown.

like image 165
F0r3v3r-A-N00b Avatar answered Sep 26 '22 00:09

F0r3v3r-A-N00b