.Net Add Index to Datatable (dataset)(.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 将索引添加到数据表(数据集)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:.Net 将索引添加到数据表(数据集)
基础教程推荐
- 全局 ASAX - 获取服务器名称 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
