Read top2000 data records cyclically

Source: Internet
Author: User

Private void xunhuan (string keyword, string filename) {try {While (true) {richtextbox1.clear (); string SQL = "select top 2000 ID, productname, merchantid, pinpai, Chandi, color, browsenodekeyword from [gwkproduct] Where ident like '"+ keyword +" _ %' and (shortintro = ''or shortintro is null)"; dataset DS = dbhelpersql. query (SQL); int COUNT = 0; // uint rowscount = 0; // dataset DS = readalldata (ref rows Count, textbox1.text. trim (); datatable dt = Ds. tables [0]; int row_count = DT. rows. count; For (Int J = 0; j <DT. rows. count; j ++) {int id = (INT) dt. rows [J] ["ID"]; string productname = DT. rows [J] ["productname"]. tostring (). replace ('\ '',''); int merchantid = (INT) dt. rows [J] ["merchantid"]; string pinpai = DT. rows [J] ["pinpai"]. tostring (). replace ('\ '',''); string Chandi = DT. rows [J] ["Chandi"]. tostr Ing (). replace ('\ '',''); string color = DT. rows [J] ["color"]. tostring (). replace ('\ '',''); string fenlei = ""; try {string browsenodekeyword = DT. rows [J] ["browsenodekeyword"]. tostring (); fenlei = dbhelpersql. getsingle ("select catname from category where curpath = '" + browsenodekeyword + "'"). tostring () ;}catch {fenlei = "";} string merchtname = dbhelpersql. getsingle ("select merchname from Merc HANT where merchid = '"+ merchantid +"' "). tostring (); string shortintro = productname +" "+ merchtname; If (pinpai! = "" & Pinpai! = NULL) {shortintro = shortintro + "brand:" + pinpai;} If (color! = "" & Color! = NULL) {shortintro = shortintro + "color:" + color;} If (Chandi! = "" & Chandi! = NULL) {shortintro = shortintro + "Origin:" + Chandi;} If (fenlei! = "") {Shortintro = shortintro + "" + fenlei ;} string strsql = "Update gwkproduct set shortintro = '" + shortintro + "'where id ='" + ID + "'"; count + = 1; dbhelpersql. executesql (strsql); richtextbox1.appendtext (count. tostring () + ". "+ strsql +" \ r \ n "); richtextbox1.scrolltocaret (); writeerr (filename, Count. tostring () + ". "+ strsql) ;}if (row_count <2000) {return ;}} catch {xunhuan (keyword, filename) ;}} public static void writeerr (string filename, string errstring) {// string errfile = application. startuppath + @ "\ back.txt"; streamwriter Sw = new streamwriter (filename, true); Sw. writeline (errstring); Sw. close () ;}// read all data cyclically public dataset readalldata (ref uint rowscount, string ident) {int getrows = 1000; // The number of records retrieved each time int rowcount = 0; // The data retrieved each time uint startid = 0; // The start read ID dataset DS = new dataset (); // read all data for (INT I = 0 ;; I ++) {datatable dt = new datatable (); dt = readdatabyfill (getrows, startid, ident); rowcount = DT. rows. count; // obtain the amount of data in the currently returned table rowscount + = uint. parse (rowcount. tostring (); If (rowscount> 0) {startid = uint. parse (DT. rows [rowcount-1] ["ID"]. tostring (); // obtain the maximum number for reference. tables. add (DT. copy (); DS. tables [I]. tablename = "TB" + I. tostring () ;}if (rowcount <getrows) {break ;}return DS ;}// generates data for the full-text New-filled index (each time the Top N records are read, in case an application occurs when reading data too slowly.Program False) Public datatable readdatabyfill (INT top, uint startid, string ident) {string SQL = "select"; if (top> 0) {SQL + = "TOP" + top. tostring ();} SQL + = "ID, productname, merchantid, pinpai, Chandi, color, browsenodekeyword from [gwkproduct] "+" where ident like '"+ ident +" _ %' and (shortintro = ''or shortintro is null) and ID>" + startid. tostring () + "order by id asc"; datatable dt = getdatatable (SQL); Return DT;} // return datatable private datatable getdatatable (string SQL) {sqlconnection conn = new sqlconnection (@ "Server = 221.122.127.101; database = gouwuke_chs; uid = admin; Pwd = 7418;"); sqldataadapter SDA = new sqldataadapter (SQL, Conn ); dataset DS = new dataset (); SDA. fill (DS); Conn. close (); Return Ds. tables [0];}

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.