Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 如何显示通过id连接的两个表中的数据?_Asp.net - Fatal编程技术网

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