动网论坛,站长建站首选,国内使用量最多的论坛软件 动网论坛官方技术讨论区 站长工具 申请属于您自己的免费论坛
首页 | 新闻资讯 | 网站运营 | 网络编程 | 数据库 | 服务器 | 网页设计 | 图像媒体 | 网络应用 | 搜索优化 | 资源下载 | 动网主机 | DVBOX
    本站内  互联网 ASP论坛  ASP.Net论坛  PHP论坛
  
   .Net → 阅读文章

 利用关联将子关联记录取出

作者来源: 
阅读 数 309 人次 , 2006-3-29 4:28:00 


关联建立之后,我们就可以享受到关联的好处了。我们可以透过datarow 对象的getchildrows以及getparentrow 方法取得记录的子记录或是父记录;这个方法接收的一个参数,就是我们加到关联集合的关联名称。下列范例将每一个使用者所下过的订单列出:

<%@import namespace=system.data.ado%>
<%@import namespace=system.data%>
<script language="vb" runat="server">
sub page_load(sender as object, e as eventargs)
dim strconstr as string = "provider=microsoft.jet.oledb.4.0;" & _
"data source=c:\inetpub\wwwroot\cr\ch05\myweb.mdb"
dim strcomstr as string = "select * from members"
dim dsca as adodatasetcommand = new adodatasetcommand(strcomstr,
strconstr)
dim dsdataset as dataset = new dataset()
dsca.filldataset(dsdataset, "members")
dsca.selectcommand.commandtext = "select * from orders"
dsca.filldataset(dsdataset, "orders")
dsdataset.relations.add("mo",
dsdataset.tables(0).columns("userid"), _
dsdataset.tables(1).columns("userid"))
dim shti as short
dim rowtemp as datarow
for shti=0 to dsdataset.tables("members").rows.count-1
response.write("使用者: " &
dsdataset.tables("members").rows(shti)("userid") & _
" 所下过的订单有:")
for each rowtemp in
dsdataset.tables("members").rows(shti).getchildrows("mo")
response.write("<br>订单日期: " & rowtemp("orderdate") & _
" / 订购产品: " & rowtemp("productname") & _
" / 产品单价: " & rowtemp("unitprice") & _
" / 订购数量: " & rowtemp("quantity") & _
" / 小计: " & rowtemp("total"))
next
response.write("<p>")
next
end sub
</script>

 
 收藏本文  打印本文  论坛讨论  关闭窗口
· 上一篇:For Each...In 循环结构
· 下一篇:定义数据表之间的关联
· 关于C#下写的Web Service 服务在Delphi下调用时的问题
· Calendar Web 控件
· 我认为JSP有问题(下)
· 部署ASP.NET的三大技术(1)
· 取出使用者所上传的参数


关于本站 | 联系我们 | 业务合作 | 客户案例 | 诚聘英才 | 广告合作 | 收藏本站
海口动网先锋网络科技有限公司版权所有
Copyright © 2000 - 2006 Cndw.Com
中华人民共和国电信与信息服务业务经营许可证编号 琼 ICP 020077