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 );}}