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

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

问题描述

有没有办法在 .Net 中为数据表添加索引?

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

我有一个包含大约 1,100 行的数据表,并且 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天全站免登陆