Default.aspx.cs文件:
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data.SqlClient; using System.Data; using System.Data.Common; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { SqlConnection con = new SqlConnection("server=hannibal-pc\\hansql;uid=sa;pwd=xiaoaiai;database=test;min pool size=10;max pool size=512"); String sql=" select * from person "; SqlDataAdapter cmd = new SqlDataAdapter(sql, con); DataSet ds = new DataSet(); cmd.Fill(ds, "person"); DataTable dt=ds.Tables[0]; DataRowCollection drc=dt.Rows; String html=""; html += "<table cellpadding=\"0\" cellspacing=\"0\" border=\"1\" >"; html += "<th>id</th>"; html += "<th>name</th>"; html += "<th>pwd</th>"; foreach(DataRow dr in drc) { html += "<tr>"; html += "<td>" + dr["id"].ToString() + "</td>"; html += "<td>" + dr["name"].ToString() + "</td>"; html += "<td>" + dr["pwd"].ToString() + "</td>"; html += "</tr>"; } html += "</table>"; this.table_html.InnerHtml = html; } }
转载于:https://blog.51cto.com/13756040010/1536252