⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 aggregatecolumn.aspx

📁 asp.net技术内幕的书配源码
💻 ASPX
字号:
<%@ 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" )
  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>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -