VS. NET (C #) Database Interface C # DataSet object access demonstration (code case), vs.net

Source: Internet
Author: User

VS. NET (C #) Database Interface C # DataSet object access demonstration (code case), vs.net

Based on the above section, output the data of the two tables created in the DataSet object to the page. Achieve the following results:

Click "Access DataSet object" to display all data tables in DataSet.

Add ShowDataSet (DataSet ds) function call by clicking an event on the button

 protected void Button1_Click(object sender, EventArgs e)    {        ShowDataSet(ds_Forum);    }
Private void ShowDataSet (DataSet ds) {// construct the output string StringBuilder htmlStr = new System. text. stringBuilder (); // traverses all tables in Forum (use foreach traversal) foreach (DataTable dt in ds. tables) {// The table starts htmlStr. append ("<table border = '1' cellPadding = '5' cellSpacing = '0' style = 'font-size: 9pt; font: '> "); # the header of the region table // the header starts htmlStr. append ("<tr style = 'background-color = # f0f0f0 '>"); // traverses all columns in the table (use for traversal) for (int I = 0; I <dt. Columns. count; I ++) {htmlStr. append (string. format ("<td> <strong> {0} </strong> </td>", dt. columns [I]. columnName); // header} htmlStr. append ("</tr>"); // end of a row in the header # endregion # data row in the region table // traverse all rows in the table for (int I = 0; I <dt. rows. count; I ++) {// The data row starts htmlStr. append ("<tr>"); // traverses the column for (int j = 0; j <dt. columns. count; j ++) {if (! Dt. rows [I]. isNull (j) {htmlStr. append (string. format ("<td> {0} </td>", dt. rows [I] [j]);} else {htmlStr. append (string. format ("<td> {0} </td>", string. empty);} // end of the Data row htmlStr. append ("</tr>") ;}# endregion // the end of the table htmlStr. append ("</table> <br>");} // output DataSet page data Response. write (htmlStr );}

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.