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

📄 datarelation.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 drowParent As DataRow
  Dim drowChild As DataRow

  ' 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( _
   "Categories_Products", _
    dstNorthwind.Tables( "Categories" ).Columns( "CategoryID" ), _
    dstNorthwind.Tables( "Products" ).Columns( "CategoryID" ) )

  ' Display each Category and Child Products
  For each drowParent in dstNorthwind.Tables( "Categories" ).Rows
    lblOutput.Text &= "<h3>" & drowParent( "CategoryName" ) & "</h3>"
    For each drowChild in drowParent.GetChildRows( "Categories_Products" )
      lblOutput.Text &= "<li>" & drowChild( "ProductName" )
    Next
  Next
End Sub
</Script>

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

<asp:Label
  ID="lblOutput"
  Runat="Server" />

</body>
</html>

⌨️ 快捷键说明

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