我想知道是否可以使用 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/