C # Resolution database with in is greater than 1000 error problem

Source: Internet
Author: User

Problem:

// Oracle Database Error Delete  from where ORDERID=in(0,1,2,3,4,5,6,7 ..... 1001);
View Code

C # has written a way to solve

/// <summary>        ///Stitching SQL/// </summary>        /// <param name= "str" >Main SQL statement</param>        /// <param name= "IDs" >parameters to stitch in inside</param>        /// <param name= "Count" >number of bars per execution</param>        /// <returns></returns>         Public Static string Get(stringStrstring[] IDs) {            if(IDs. Length >0) {StringBuilder sb=NewStringBuilder ();  for(inti =0; I < IDs. Length; i++)                {                    if((i% +) ==0&& i >0) {sb. Remove (sb.) Length-1,1); Sb. Append (") or"+ str +"In ("+ Ids[i] +","); }                    Else{sb. Append (Ids[i]+","); }} sb. Remove (sb.) Length-1,1); returnSTR +"In ("+ sb. ToString () +")"; }            return ""; }
View Code

Call the following

 Static voidMain (string[] args) {            stringstr ="Delete from dd_order_detail where ORDERID ="; string[] s = { }; List<string> list =Newlist<string>();  for(inti =0; I <1001; i++) {list.            ADD (i.ToString ()); } s=list.            ToArray ();            Console.WriteLine (s.length); stringSS =Get(str, s);        Console.readkey (); }
View Code

The effect is as follows

C # Resolution database with in is greater than 1000 error problem

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.