.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 将索引添加到数据表(数据集)


基础教程推荐
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01
- rabbitmq 的 REST API 2022-01-01
- SSE 浮点算术是否可重现? 2022-01-01
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- c# Math.Sqrt 实现 2022-01-01
- MS Visual Studio .NET 的替代品 2022-01-01
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01
- 将 XML 转换为通用列表 2022-01-01
- 如何激活MC67中的红灯 2022-01-01