简体   繁体   English

如何使用ADO.Net从数据表中选择数据?

[英]How to use ADO.Net to select data from a DataTable?

Using: ado.net How can I select data from a DataTable using SQL with an aggregation function? 使用:ado.net如何使用带有聚合功能的SQL从数据表中选择数据? I know that I can use select property ( http://msdn.microsoft.com/en-us/library/t5ce3dyt(vs.71).aspx ) but I need an aggregation function to use it with, and I didn't find any examples for this. 我知道我可以使用select属性( http://msdn.microsoft.com/en-us/library/t5ce3dyt(vs.71).aspx ),但是我需要一个聚合函数来使用它,但是我没有查找有关此示例。

Aggregates in DataSet are normally used in conjunction with relations: DataSet中的聚合通常与关系一起使用:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemdatadatacolumnclassexpressiontopic.asp http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemdatadatacolumnclassexpressiontopic.asp

Basically if you need your result as single row with single column, you'd need to create that extra table with that column and add expression to it so you would get a single row: 基本上,如果您需要将结果作为具有单列的单行,则需要使用该列创建该额外的表并向其中添加表达式,以便获得单行:

Table1, column Number: 3 rows containing 1,2,3 表1栏数:3行包含1,2,3

Table2, column Average, expression set to "Avg(Table1.Number)": One rows containing 2 表2,“平均值”列,将表达式设置为“ Avg(Table1.Number)”:包含2行

As to your particular example: "SELECT COUNT(*) FROM ", you could use row count: table.Rows.Count 对于您的特定示例:“ SELECT COUNT(*)FROM”,您可以使用行数:table.Rows.Count

You can also create DataView with particular filter and get number of rows in it to emulate more complex cases of COUNT. 您还可以使用特定的过滤器创建DataView并获取其中的行数,以模拟更复杂的COUNT情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM