ASP.NET使用表别名进行多表查询
一、程序功能:将orders表和customers表中的字段绑定到文本框
二、窗体设计
1、新建asp.net web应用程序,命名为sql4,选择保存路径然后点击确定。
2、向窗体中添加两个label和两个textbox控件,窗体界面见下图
三、代码设计
切换到代码窗口,添加代码如下:
imports system.data.sqlclient
public class webform1
inherits system.web.ui.page
private sub page_load(byval sender as system.object, byval e as system.eventargs) handles mybase.load
dim scon as new sqlconnection("server=localhost;database=northwind;integrated security=true")
dim i as integer = 10248
'创建一个数据适配器,查询订单表中的订单号和客户表的公司名称,此处使用了表格别名
dim sda as new sqldataadapter _
("select o.orderid, c.companyname from orders o, customers c where o.customerid=c.customerid and o.orderid=" & i.tostring, scon)
dim ds as new dataset
try
sda.fill(ds)
catch ex as exception(www.iocblog.net 文章来源)
end try
'绑定数据
textbox1.text = ds.tables(0).rows(0).item(0)
textbox2.text = ds.tables(0).rows(0).item(1)
end sub
end class(www.iocblog.net 文章来源)
文章整理:iocblog
版权申明:本站文章均来自网络,如有侵权,请联系我们,我们收到后立即删除,谢谢!
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有。