c# - 是否可以使用 SQL 查询搜索 DataGridView 或 DataTable

标签 c# sql database datagridview datatable

我想知道是否可以使用 SQL 查询来搜索 DataGridView 或 DataTable。

我有几列,想搜索具有给定条件集的结果(例如,列 a = x 和列 b < 3)。还是我必须为此使用数据库?

最佳答案

您可以在 DataTable 上使用 Linq 查询(不建议查询 DataGrid)

DataTable orders = ds.Tables["SalesOrderHeader"];

// Query the SalesOrderHeader table for orders using linq
IEnumerable<DataRow> query =
    from order in orders.AsEnumerable()
    where order.Field<DateTime>("OrderDate") > new DateTime(2001, 8, 1)
    select order;

关于c# - 是否可以使用 SQL 查询搜索 DataGridView 或 DataTable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51890654/

相关文章:

javascript - 如何找出 JavaScript Promise 中返回的类型

c# - 检查两个列表中的重复项

c# - System.AccessViolationException 的奇怪问题

MySQL:仅获取当前未事件计划的对象

sql - 将 Crystal Reports 连接到 SQL Server

sql - 有没有办法使用 Windows 身份验证为 ms sql 显式指定 u/p?

database - 如何处理引用可变表的不可变表?

c# - 如何删除不需要的行

c# - Linq,如何使用子查询?

php - 加入 2 个 SQL 表并显示在 1 个 PHP 表中