Asp.net 如何显示通过id连接的两个表中的数据?
我有两张桌子,上面有:Asp.net 如何显示通过id连接的两个表中的数据?,asp.net,Asp.net,我有两张桌子,上面有: table 1 sid, schedule, stime, splace, stourid table 2 tourid, tourname 我想在网格视图中显示表1,但使用字段stourid我想显示table 2中的tourname,而不是stourid。如何执行此操作?对数据执行以下SQL语句,将结果绑定到表中,并仅显示希望显示的列 select * from table1 join table2 on table1.tourid = table2.tourid
table 1
sid, schedule, stime, splace, stourid
table 2
tourid, tourname
我想在网格视图中显示
表1
,但使用字段stourid
我想显示table 2
中的tourname
,而不是stourid
。如何执行此操作?对数据执行以下SQL语句,将结果绑定到表中,并仅显示希望显示的列
select * from table1 join table2 on table1.tourid = table2.tourid
您可以使用
Join
查询:
SELECT sid, schedule, stime, splace, tourname
FROM table1 INNER JOIN table2 ON table1.stourid = table2.tourid
使用内部连接
select t1.sid,t1.schedule,t1.stime,t1.splace,t2.tourname from table1 t1 inner join table2 t2 on t1.tourid = t2.tourid
选择sid、计划、时间、splace、tourname 从表1交叉连接
表2假设上面的stourid是表2的指针并映射到tourid,我将在tourid/stourid上创建一个带有连接的视图并显示该视图。比如:
CREATE VIEW myView
AS
SELECT sid, schedule, stime, splace, tourname
FROM
[table 1] AS t1
JOIN [table 2] AS t2
ON t1.stourid = t2.tourid