在asp.net的网格视图中联接具有相同ID的两个表的数据 [英] join data of two table with same id in grid view in asp.net

查看:88
本文介绍了在asp.net的网格视图中联接具有相同ID的两个表的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在两个表中都有两个表,我有一个公共列,我想将这两个表与该公共列在网格视图中连接起来,例如
表1
------
id,
名称,
城市

table2
------
id,
地址

我想要两个表中具有相同ID的列.

我用过

i have two tables in both tables i have one common column and i want join these two table with that common column in grid view for eg
table1
------
id,
name,
city

table2
------
id,
address

i want those columns which have the same id in the both tables.

i used

select * from table1 inner join table2 on table1.id = table2.id


但这显示了无效的对象名称的错误


but this is showing an error of invalid object name

推荐答案

Try:
Try:
SELECT t1.id, t1.name, t1.city , t2.address
FROM [YourDatabaseName].[dbo].[table1] AS t1 LEFT JOIN [YourDatabaseName].[dbo].[table2] AS t2 on t1.id = t2.id



这意味着:从表1中选择所有数据,并从表2中选择相应的数据.



This mean: select all data from table1 and corresponding data from table2.


这篇关于在asp.net的网格视图中联接具有相同ID的两个表的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆