关于DataRepations的问题

nnh 2006-03-31 01:48:10
代码如下:
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>

<Script Runat="Server">

Sub Page_Load
Dim dstNorthwind As DataSet
Dim conNorthwind As SqlConnection
Dim dadNorthwind As SqlDataAdapter
Dim dcolProductCount As DataColumn

' Grab the Categories and Products table
dstNorthwind = New DataSet()
'conNorthwind = New SqlConnection( "Server=localhost;UID=sa;PWD=secret;Database=Northwind" )
conNorthwind = New SqlConnection( "Server=p085;UID=sa;PWD=;Database=Northwind" )
dadNorthwind = New SqlDataAdapter( "Select * From Categories", conNorthwind )
conNorthwind.Open()
dadNorthwind.Fill( dstNorthwind, "Categories" )
dadNorthwind.SelectCommand = New SqlCommand( "Select * From Products", conNorthwind )
dadNorthwind.Fill( dstNorthwind, "Products" )
conNorthwind.Close()

' Add Parent/Child Relationship
dstNorthwind.Relations.Add( _
"catprods", _
dstNorthwind.Tables( "Categories" ).Columns( "CategoryID" ), _
dstNorthwind.Tables( "Products" ).Columns( "CategoryID" ) )

' Add the aggregate column
dcolProductCount = New DataColumn( "ProductCount", GetType( Decimal ) )
dcolProductCount.Expression = "Count( Child.ProductID )"
dstNorthwind.Tables( "Categories" ).Columns.Add( dcolProductCount )

' Bind to the DataGrid
dgrdNorthwind.DataSource = dstNorthwind
dgrdNorthwind.DataMember = "Categories"
dgrdNorthwind.DataBind()
End Sub
</Script>

<html>
<head><title>AggregateColumn.aspx</title></head>
<body>

<asp:DataGrid
ID="dgrdNorthwind"
Runat="Server" />

</body>
</html>



我对这一句 dcolProductCount.Expression = "Count( Child.ProductID )"
不是很明白,请大家帮忙解释一下,谢谢
...全文
81 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
mextb1860 2006-04-26
  • 打赏
  • 举报
回复
那是干嘛用的
zhouheng123456 2006-04-25
  • 打赏
  • 举报
回复
偶也没用过...嘿嘿...
menuvb 2006-04-25
  • 打赏
  • 举报
回复
从来没用过。根据MSDN的定义:创建计算出的列和创建聚合列

DataSet1.Tables("Orders").Columns("OrderCount").Expression = "Count(OrderID)"

可以查查MSDN
nnh 2006-04-25
  • 打赏
  • 举报
回复
没有人会吗 ?
nnh 2006-04-18
  • 打赏
  • 举报
回复
帮帮忙呀.
nnh 2006-04-03
  • 打赏
  • 举报
回复
up
自由人2008 2006-03-31
  • 打赏
  • 举报
回复
用于计算列中的值或创建聚合列。
很好用。
你这里的意思就是说.dcolProductCount这一列的值=Count( Child.ProductID )

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧