在aspx.cs中填写下列代码
被注释的是可以动态添加table是数据显示
没被注释的是可以显示在特定的ID中的;
using (SqlConnection conn = new SqlConnection(connStr))
{
conn.Open();
using (SqlCommand cmd = conn.CreateCommand())
{
cmd.CommandText = "select * from eBookxinxi";
//cmd.Parameters.Add(new SqlParameter("UserName", textBox1.Text));
using (SqlDataReader reader = cmd.ExecuteReader())
{
for (int i = 0; reader.Read(); i++)
{
//TableRow Row = new TableRow();//新建添加行
//Row.BorderWidth = 1;
//string yourColor = "#FF0000";
//Row.BorderColor = Color.FromName(yourColor);
//TableCell Cell = new TableCell();
//int ids = reader.GetInt32(reader.GetOrdinal("FId"));
//Cell.Text = ids.ToString();
//Cell.BorderWidth = 1;
//Cell.BorderColor = Color.FromName(yourColor);
//Row.Cells.Add(Cell);
//TableCell Cell1 = new TableCell();//新建添加列
string username = reader.GetString(reader.GetOrdinal("eBtj"));
tj.InnerText = username;
//Cell1.Text = "<a href='http://www.baidu.com'>" + username + "</a>";
//Cell1.BorderWidth = 1;
//Cell1.BorderColor = Color.FromName(yourColor);
//Row.Cells.Add(Cell1);
//Table1.Rows.Add(Row);
}
}
}
}