Contents of a table in the database

Source: Internet
Author: User

Aspx code:

<% @ Page Language = "C #" autoeventwireup = "true" codefile = "default. aspx. cs" inherits = "_ default" DEBUG = "true" %>

<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head runat = "server">
<Title> default. aspx </title>
</Head>
<Body>
<Form ID = "form1" runat = "server">
<Div style = "font-size: 12px; text-align: center;"> content of a table in the database (for details about the loop concept, see) </div>
<Asp: Label id = "lblcomment" runat = "server"> </ASP: Label>
</Form>
</Body>
</Html>

CS code:

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 _ default: system. Web. UI. Page
{
Protected void page_load (Object sender, eventargs E)
{
// WebService Ws = new WebService ();
Lblcomment. Text = gettablecontent (". // sqlexpress", "video", "sa", "111", "v_rate ");
}
/// <Summary>
/// View the content of a table (five parameters)
/// </Summary>
/// <Param name = "host"> database server name </param>
/// <Param name = "Database"> database name </param>
/// <Param name = "uid"> Database User Name </param>
/// <Param name = "PWD"> Database User Password </param>
/// <Param name = "table"> name of the table in the database </param>
/// <Returns> </returns>
Public String gettablecontent (string host, string database, string uid, string PWD, string table)
{
String cnstr = "Server =" + host + "; database =" + database + "; uid =" + uid + "; Pwd =" + PWD + ";";
Sqlconnection conn = new sqlconnection (cnstr );
Sqldataadapter cmd = new sqldataadapter ("select * from" + Table, Conn );
Dataset DS = new dataset ();
Cmd. Fill (DS, "table ");
Datatable DT;
Dt = Ds. Tables ["table"];

String rsstring;
Rsstring = "<Table width =/" 100%/"border =/" 0/"bgcolor =/" #333333/"cellpadding =/" 1/"cellspacing =/" 1/ "Style =/" font-size: 12px;/">"
+ "<Tr bgcolor =/" White/"> ";
For (INT I = 0; I <= DT. Columns. Count-1; I ++)
{
Rsstring + = "<TD>" + dt. Columns [I]. columnname + "</TD> ";
}
Rsstring + = "</tr> ";
For (INT I = 0; I <DT. Rows. Count; I ++)
{
Rsstring + = "<tr bgcolor =/" White/"> ";
For (Int J = 0; j <= DT. Columns. Count-1; j ++)
{
Rsstring + = "<TD>" + dt. Rows [I] [J] + "</TD> ";
}
Rsstring + = "</tr> ";
}
Rsstring + = "</table> ";
Return rsstring;
}
}
 

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.