很有趣的一个sql查询语句,大家帮忙看看

满天都是小星星_1 2017-07-06 08:24:30
用IN语句
select * from otim where sheetid in('A','B','C')

问题来了,查询值不为ABC,是动态获取listBox2.Items所有项
  for (int i = 0; i < listBox2.Items.Count; i++)
{
string name0 = listBox2.Items[i].ToString();
// string sqlQuery = "";
}

查询语句sqlQuery 又该怎样写呢??
...全文
218 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
npc10101 2017-07-06
  • 打赏
  • 举报
回复
半小时就自己解决了呢
  • 打赏
  • 举报
回复
就是个简单的字符串数组拼接

    string[] arrayC= new string[listBox2.Items.Count];
            for (int i = 0; i < listBox2.Items.Count; i++)
            {                   
                arrayC[i] = listBox2.Items[i].ToString();           
            }
            string instrin = string.Join("','", arrayC);
            string sqlQuery = "select * from otim where sheetid in("+"'" + instrin + "'"+")"; 
二月十六 版主 2017-07-06
  • 打赏
  • 举报
回复
  • 打赏
  • 举报
回复
好了,自己解决了
  • 打赏
  • 举报
回复
或者是使用字符串拼接吗?
  • 打赏
  • 举报
回复
in('A','B','C')用数组代替吗?咋写?

34,593

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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