实体类参数化查询多个栏目的记录,SQL语句怎么写?

clm0010 2009-10-28 01:55:45
文章标题列表查询,单个栏目ID
//根据栏目ID,返回文章DataSet
public DataSet getArticleDataSetByClassid(article classID)
{
DbCommand cmd = DB.GetSqlStringCommond("select * from jsArticle where classid=@classid");
DB.AddInParameter(cmd, "@classID", DbType.String, ar.ClassID);
DataSet myDataSet = DB.ExecuteDataSet(cmd);
return myDataSet;
}

如果classid有多个,select * from jsArticle where classid in(@classids) 的时候,应该怎么写?

迷糊了很多天,希望大家帮帮我。
...全文
168 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
tzs2304 2009-10-28
  • 打赏
  • 举报
回复
帮顶
clm0010 2009-10-28
  • 打赏
  • 举报
回复
谢谢大家早上这么踊跃发言,提供了这么多好方法,每一种方法我都会尝试,然后总结一下,已备后人使用。
gongsun 2009-10-28
  • 打赏
  • 举报
回复
...
wuyq11 2009-10-28
  • 打赏
  • 举报
回复
string classID="";
List<article> lst=new List<article>();
foreach(article ar in lst)
{
classID=ar.ClassID+",";
}
if(classID.EndsWith(",") classID="("+classID.Substring(0,classID.Length-1)+")";

DbCommand cmd = DB.GetSqlStringCommond("select * from jsArticle where classid in @classid");
小芝麻 2009-10-28
  • 打赏
  • 举报
回复
我一般是用select * from jsArticle where classid in(1,2,3,4)
你用参数的话可以把中间的作为一个string类型的参数啊
liaoyukun111 2009-10-28
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 findcaiyzh 的回复:]
另一个方法是分别取得结果,然后调用
DataTable.Merge Method (DataTable)
Merge the specified DataTable with the current DataTable.


[/Quote]
很牛 反正取出前后都是可以操作的
yzf86211861 2009-10-28
  • 打赏
  • 举报
回复
另一个方法是分别取得结果,然后调用
DataTable.Merge Method (DataTable)
Merge the specified DataTable with the current DataTable.

jenny0810 2009-10-28
  • 打赏
  • 举报
回复
帮顶 期待高人用参数化写一个
zhong2006 2009-10-28
  • 打赏
  • 举报
回复
select * from jsArticle where classid in(1,2,3,4) 直接就这样写
takako_mu 2009-10-28
  • 打赏
  • 举报
回复
大家都說了。。我一般是用1樓這種,先拼在一起,再帶入。
宝_爸 2009-10-28
  • 打赏
  • 举报
回复
另一个方法是分别取得结果,然后调用
DataTable.Merge Method (DataTable)
Merge the specified DataTable with the current DataTable.

xuStanly 2009-10-28
  • 打赏
  • 举报
回复
另外写个方法,用string传入多个classid,组织成1,2,3,4之类的格式,
然后replace掉select * from jsArticle where classid in(@classids)
里面的@classids,注意过滤以防止注入。

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧