关于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 )"
不是很明白,请大家帮忙解释一下,谢谢