求助,看这条语句 string.Format("select GoodsName from Goods where ID='{0}'", id) id为方法的参数 问题:当id为一个数组的时候这条语句怎么写?因为id是别的方法返回的 
string[] 要是循环这个数组一条一条查的话几十万条记录不卡死~~ 我记着好像可以select GoodsName from Goods where ID in ??? 
怎么写 
是oracle数据库 
或者有什么别的方法?讲究效率,因为别的方法返回的是个参数数组string []

解决方案 »

  1.   

    string.Format("select GoodsName from Goods where ID in {0}", string[]) 
    试试…
      

  2.   

    select * from product where id in{1,2,3} 这个在sql中也有同样的语法
      

  3.   

    好像是select * from tablename where id in (select id from tablename);
    不想实现select * from tablename where id in (你的方法())对吧,你自己试试
      

  4.   


            Dim id() As String = {"1", "2", "3"}        Dim str As String = String.Empty        For Each s In id
                str = str & s & ","
            Next
            str = String.Format("select GoodsName from Goods where ID in ({0})", str.Substring(0, str.Length - 1))        MessageBox.Show(str)
      

  5.   


    string[] ids = 从其他地方得到的一个字符串数组;
    string sql = string.Format("selectGoodsName from Goods where ID in ({0})", string.Join(",",ids)); 
      

  6.   


    用in的效率很低
    能用=尽量别用in还是循环吧for(int i = 0; i< str[].length; i++)
    {
    string.Format("select GoodsName from Goods where ID in {0}", str[i]) ;
    }或者拼成or语句
      

  7.   

    还是这个好 string.Join,看了半天Array的join,找不到,哈哈
      

  8.   

    呵呵,谢谢各位,拼接的话也可以,用那个string.Join也行~~我其实主要是看那种方法效率好~~因为返回的记录太多,几十万条,放在数组里面,循环数组每次都查数据库,太慢,用in的话查询一次倒是可以,但是记录几十万条的话拼接起来的SQL都得多长,好像系统也不支持吧,刚才报错说表达式最大为1000
    求求各位看有什么好方法
      

  9.   

    没多大区别,如果查询表中的所有记录,那就不要根where语句,如果查询的数量过半,那就用not in
    如果少于一半,就用in
    其实都没多大区别的
      

  10.   

     Dim id() As String = {"1", "2", "3"}        Dim str As String = String.Empty        For Each s In id
                str = str & s & ","
            Next
            str = String.Format("select GoodsName from Goods where ID in ({0})", str.Substring(0, str.Length - 1))        MessageBox.Show(str)