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

📄 aggregatecolumn.aspx

📁 asp.net技术内幕的书配源码
💻 ASPX
字号:
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>

<script runat=server>

void Page_Load(Object sender , EventArgs e) 
{
	DataSet dstNorthwind; 
	SqlConnection conNorthwind;
	SqlDataAdapter dadNorthwind;
	DataColumn dcolProductCount;

	//Grab the Categories and Products table
	dstNorthwind = new DataSet();
	conNorthwind = new SqlConnection( @"Server=localhost;Integrated Security=SSPI;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"), System.Type.GetType("System.Decimal"));
	dcolProductCount.Expression = "Count( Child.ProductID )";
	dstNorthwind.Tables[ "Categories" ].Columns.Add( dcolProductCount );

	//Bind to the DataGrid
	dgrdNorthwind.DataSource = dstNorthwind;
	dgrdNorthwind.DataMember = "Categories";
	dgrdNorthwind.DataBind();
}
</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 + -