.Net向数据表(数据集)添加索引 [英] .Net Add Index to Datatable (dataset)

查看:85
本文介绍了.Net向数据表(数据集)添加索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种方法可以向.Net中的数据表添加索引?

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

我有一个约1100行的数据表,而datatable.select语句对于内存中操作似乎有点慢。

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

推荐答案

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

搜索时

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.

这篇关于.Net向数据表(数据集)添加索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆