zoukankan      html  css  js  c++  java
  • 使用SQL查询语句时,数组动态赋值SQL IN ()作为条件条件一个 子曰

       遇到一个问题,前台传过来一个包含多个id值拼接起来的字符串,例如"23,56,36”作为一个查询条件。

       问题出来了。这个字符串中的数字都已经为字符型了,而表中的对应的id列为整形。如果直接用select.....from..where id in('23,56,36')这种形式肯定会报错。在想了众多办法后,觉得在把这个字符串离得数字提出来,并转换成int,然后再拼接成一个查询字符串,这个方法相对简单一点。

         
     
             string strorderfromId = Request.Form["strorderfromId"];
            string[] sArray=strorderfromId.Split(',');
            string ss = "orderform.dd_date <='" + date + "' AND orderform.id in(";
                for (int i = 0; i < sArray.Length; i++)
    
                {
                    ss = ss + sArray[i] + ",";
                   
                }
                ss = ss.Substring(0, ss.Length - 2);
                ss = ss + ")";
                ds = bll.GetList(ss);
    

    
    
  • 相关阅读:
    c++学习记录(七)
    c++学习记录(六)
    c++学习记录(五)
    c++学习记录(四)
    2020面向对象寒假作业(二)
    2020面向对象寒假作业(二)
    HTML学习记录(一)
    我罗斯方块
    我罗斯
    面向对象程序设计3
  • 原文地址:https://www.cnblogs.com/suixufeng/p/3336140.html
Copyright © 2011-2022 走看看