惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Google DeepMind News
Google DeepMind News
D
DataBreaches.Net
C
Check Point Blog
I
InfoQ
A
About on SuperTechFans
Engineering at Meta
Engineering at Meta
月光博客
月光博客
Recent Announcements
Recent Announcements
酷 壳 – CoolShell
酷 壳 – CoolShell
T
Tailwind CSS Blog
Y
Y Combinator Blog
博客园 - Franky
博客园_首页
罗磊的独立博客
量子位
美团技术团队
T
The Blog of Author Tim Ferriss
Last Week in AI
Last Week in AI
大猫的无限游戏
大猫的无限游戏
爱范儿
爱范儿
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Martin Fowler
Martin Fowler
博客园 - 叶小钗
aimingoo的专栏
aimingoo的专栏

博客园 - Eric.Chai

在WebService中不能返回SqlDataReader 控件生命周期 Solution:TF10216: Team Foundation services are currently unavailable SelectedValue小技巧 web.config点滴:更改login控件对密码安全性的要求 ASP.NET2.0网站配置的数据库连接失败问题 什么是LINQ? MSCRM自动填写当前时间 DIV和SPAN的区别 MSCRM3.0备份与还原 MSCRM IFrame 应用 关于界面元素的隐藏 ASP.NET(c#)实现防止同一用户同时登陆 “奇怪”的数据类型 简体中文转换繁体中文 C#读文本文件 DatSet与DataTable的关系 SharePoint Server 2007 Web内容管理中的几个关键概念 英语面试题 --Algorithms
使用数组动态赋值SQL IN ()条件
Eric.Chai · 2008-03-11 · via 博客园 - Eric.Chai

VB
sql = "SELECT * FROM TABLE WHERE AA IN (" '初始化查询字符串
For i = 0 to UBound(Ary) '从0循环到数组最大下标
sql = sql & Ary(i) & "," '将数组中每个值加在查询字符串后面
Next
sql = Left(sql,Len(sql)-1) & ")" '将最后一个逗号换为反括号

C#

static void Main(string[] args)
  {
  
    string str = "aaaa,bbbb,cccc,dddd,eeee";

    string[] condititons = str.Split(',');

  
   string ss = "select * from table where aa in (";
   for (int i=0;i<condititons.Length;i++)
   {
    ss = ss+condititons[i]+",";
   }
   //sql.Substring(0,sql.Length-1);
   //ss = ss.Substring(0,sql.Length-1);
   ss = ss.Substring(0,ss.Length-1);
   ss = ss +")";
   Console.WriteLine(ss);

  }
 }