Extract data from the data table to generate html

Source: Internet
Author: User

1. This problem is often encountered during office automation. You need to extract data from the database and generate HTML statements.
2. Send the HTM to the email.

 
Public static dataset getdataset (string strcommandstring, string strtablename) // get DS {open (); sqldataadapter adadapter = new sqldataadapter (); adadapter. selectcommand = new sqlcommand (strcommandstring, myconnection); dataset dsdataset = new dataset (); dsdataset. clear (); adadapter. fill (dsdataset, strtablename); Return dsdataset ;}
Using system; using system. data; using system. configuration; using system. collections; using system. web; using system. web. security; using system. web. ui; using system. web. UI. webcontrols; using system. web. UI. webcontrols. webparts; using system. web. UI. htmlcontrols; using system. data. sqlclient; public partial class testhtm: system. web. UI. page {public static string data = string. empty; protected void page_load (Object sender, eventargs e) {string strsql = "select top 10 item, u_m from item"; string strtable = "item"; HTML (dataaccess. dabaseaccess. getdataset (strsql, strtable);} protected void HTML (Dataset DS) // generate HTML {foreach (datarow J in DS. tables [0]. rows) {string sh_bz = string. empty; Data + = "<tr>"; foreach (datacolumn I in DS. tables [0]. columns) {Data + = "<TD"; // data + = I. columnname. tostring (). replace ("/'","//'"). trim (); // data + = ":"; sh_bz = J [I]. tostring (). replace ("'","//'"). trim (); Data + = "Title =/" "+ sh_bz +"/">"; if (sh_bz.length> 30) {Data + = sh_bz.substring (0, 30) + "... ";}else {Data + = sh_bz;} Data + =" </TD> ";}data + =" </tr> ";}// DATA = data. substring (0, Data. length-1 ); data = "/'<Table cellpadding =/" 0/"cellspacing =/" 0/"> <tr> <TD class =/" li_1/"> material encoding </TD> <TD class =/"li_2/"> Unit </TD> </tr> "+ Data +" </table> /'"; response. write (data );}}

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.