Project-simple export of CSV files

Source: Internet
Author: User
// Export protected void btnoutput_click (Object sender, eventargs e) {// role initialroles (); datatable dt = dbclass. getdatatable (string. format (@ "select * from {0} order by Sn DESC", view (where); stringwriter Sw = new stringwriter (); // The 4s store cannot see the relevant fields such as the Headquarters price if (umrolenames. contains ("4 s") {Sw = get4sstr (DT);} else {Sw = getadminstr (DT);} SW. close (); response. addheader ("content-disposition", "attachment; filename =" + datetime. now. tostring ("yyyymmddhhmmss") + ". CSV "); response. contenttype = "application/MS-excel"; response. contentencoding = system. text. encoding. getencoding ("gb2312"); response. write (SW); response. end ();}
// 4S Shop stitching protected stringwriter get4sstr (datatable DT) {stringwriter Sw = new stringwriter (); Sw. writeline (@ "purchase order number, region, 4S Shop Name, brand, part code, part name, model code, quantity, 4S cost price, Headquarters Purchase unit price, Headquarters Purchase total, 4s stores save money, suppliers, required arrival date, actual arrival date, 4S purchase discount "); foreach (datarow DR in DT. rows) {SW. writeline (Dr ["Sn"]. tostring () + "," + Dr ["firstarea"]. tostring () + "," + Dr ["shopname"]. tostring () + "," + Dr ["shopbrand"]. tostring () + "," + "'" + Dr ["PNO"]. tostring () + "," + Dr ["pname"]. tostring () + "," + Dr ["pcarnumber"]. tostring () + "," + Dr ["buynumber"]. tostring () + "," + Dr ["PSRP"]. tostring () + "," + Dr ["adminprice"]. tostring () + "," + Dr ["sum4sprice"]. tostring () + "," + Dr ["thriftprofit4s"]. tostring () + "," + Dr ["ooffer"]. tostring () + "," + Dr ["ojiaohuodate"]. tostring () + "," + Dr ["realreachdate"]. tostring () + "," + Dr ["discount4s"]. tostring ();} return SW ;}

  

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.