[英]C# Datagridview Run “SELECT Raw_Cab.CAB, Count(*) AS Total”
I want to run a query over a datagridview1 who is filled with this data: 我想对填充有此数据的datagridview1进行查询:
Nr Name Cost
姓名费用
125 NAME1 1
125名1 1
126 NAME1 2
126名1 2
127 NAME1 1
127名1 1
128 NAME2 1
128 NAME2 1
129 NAME2 2
129名2 2
130 NAME4 1
130名4 1
131 NAME1 1
131名1 1
The data is added programmatically from a external txt source. 数据以编程方式从外部txt源添加。
Normally if you use a query and a database the text would be : 通常,如果您使用查询和数据库,则文本为:
SELECT Raw_Cab.Name, Count(*) AS Total FROM Raw_Cab GROUP BY Raw_Cab.Name;
And the result would be 结果将是
CAB Total
CAB总计
NAME1 5 NAME2 3 NAME4 1
Is there a way to get the same result but then directly from a datagrid into an object or another datagrid? 有没有一种方法可以得到相同的结果,然后直接从一个数据网格转换为一个对象或另一个数据网格?
Alex 亚历克斯
I am not sure what is the goal, but if I understand correctly, you would like to pass a filter expression on the datagrid? 我不确定目标是什么,但是如果我理解正确,您想在datagrid上传递过滤器表达式吗? You can do it on the grid view, using this code:
您可以使用以下代码在网格视图上进行操作:
(dataGridView.DataSource as DataTable).DefaultView.RowFilter = string.Format("Total < '{0}'", 5);
More on it can be found here: 可以在这里找到更多信息:
http://msdn.microsoft.com/en-us/library/system.data.dataview.rowfilter(v=vs.110).aspx http://msdn.microsoft.com/zh-CN/library/system.data.dataview.rowfilter(v=vs.110).aspx
我通过安装Xammp并在其上运行mysql查询解决了所有问题
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.