.Net Add Index to Datatable (dataset)

时光总嘲笑我的痴心妄想 提交于 2019-12-23 17:34:55

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/37016084/net-add-index-to-datatable-dataset

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!