asp.net C#怎么实现对同一数据库的两个表的连接, 请给出类似下列语句的代码

[复制链接]
查看11 | 回复3 | 2013-3-20 00:37:28 | 显示全部楼层 |阅读模式
1. 首先,这两个表要有关系(比如主外);2. 将有关系的键作为条件添加到where中;如:表t_message_info(c_id(primary key),c_name,c_type_id)表t_message_type(t_id,t_name)select *from t_message_info m,t_message_type t where m.c_type_id = t.t_id;或者可以使用子查询:select m.c_id, m.c_name, (select t.t_name from t_message_type t where t.t_id = m.c_type_id) from t_messag...
回复

使用道具 举报

千问 | 2013-3-20 00:37:28 | 显示全部楼层
DataTable dt1=new DataTable();SqlDataAdapter sdr1=new SqlDataAdapter(".....");sdr1.Fill(dt1);DataTable dt2=new DataTable();SqlDataAdapter sdr2=new SqlDataAdapter(".....")...
回复

使用道具 举报

千问 | 2013-3-20 00:37:28 | 显示全部楼层
SQL语句本身就能实现对两个表的查询select A.*,B.* from A表 ,B表 where A.ID=B.ID 只需要一次交互就能取出需要的数据...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行