首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

SQL子查询

2012-04-27 
SQL子查询求助这是普通的子查询Select * from 表1 where id in (select id from 表2 条件)我现在 已知表2

SQL子查询求助
这是普通的子查询
Select * from 表1 where id in (select id from 表2 条件)
我现在 已知表2的ID 都保存在string[] str 这样一个数组里
我现在用LINQ该怎么查询
我用ADO.net的话怎么查询 
我用存储过程 该怎么查询 

我想把变量传进去 该传一个什么模式的? 是字符串 “ID1,ID2,ID3”最后组成
Select * from 表1 where id in “ID1,ID2,ID3” 这种格式 还是 别的格式呢

求标点 也正确 和LINQ的查询方法

[解决办法]
你表2的ID 都保存在string[] str与select id from 表2 条件有关系么?难道select id from 表2 条件查询的结果存储到string[]里面的吗?那直接把string[]连接起来,sql语句用charindex
Select * from 表1 where charindex(id,连接起来的字符串)
[解决办法]
linq查询方法

var r = from a in table1
join b in table2 on a.id equals b.table1Id
where str.Contains(b.id.ToString())
select a;

热点排行