您的位置:首页 > 数据库

dataset 操作数据库 读取数据并列表显示

2014-08-06 10:22 369 查看
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;
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  dataset 操作数据库
相关文章推荐