如何将数据库查询的内容在一个页面表格中显示
关注:233 答案:2 手机版
解决时间 2021-03-06 09:01
- 提问者网友:妳有我霸氣嗎
- 2021-03-05 16:21
如何将数据库查询的内容在一个页面表格中显示
最佳答案
- 二级知识专家网友:招人烦°惹人厌
- 2021-03-05 17:32
using using System.Web.UI.HtmlControls;
在你的table的位置放一个PlaceHolder
然后,在查询按钮的代码里写:
string 条件=" name='"+TextBox1.Text+"' and ....."; //用你的textbox构造起来的sql查询条件
string sql="select * from 表 where "+ 条件; //查询的sql语句。
DataTable dt = new DataTable();
SqlConnection conn = new SqlConnection("数据库连接字符串");
conn.Open();
SqlDataAdapter da = new SqlDataAdapter(sql, conn); ;
da.Fill(dt);
conn.Close();
Table t=new Table();
for (int i = 0; i < dt.Rows.Count; i++)
{
TableRow r = new TableRow();
TableCell c = new TableCell();
c.Text = dt.Rows[i][0].ToString();
r.Cells.Add(c);
t.Rows.Add(r);
}
PlaceHolder1.Controls.Add(t);
在你的table的位置放一个PlaceHolder
然后,在查询按钮的代码里写:
string 条件=" name='"+TextBox1.Text+"' and ....."; //用你的textbox构造起来的sql查询条件
string sql="select * from 表 where "+ 条件; //查询的sql语句。
DataTable dt = new DataTable();
SqlConnection conn = new SqlConnection("数据库连接字符串");
conn.Open();
SqlDataAdapter da = new SqlDataAdapter(sql, conn); ;
da.Fill(dt);
conn.Close();
Table t=new Table();
for (int i = 0; i < dt.Rows.Count; i++)
{
TableRow r = new TableRow();
TableCell c = new TableCell();
c.Text = dt.Rows[i][0].ToString();
r.Cells.Add(c);
t.Rows.Add(r);
}
PlaceHolder1.Controls.Add(t);
全部回答
- 1楼网友:单剑走天涯
- 2021-03-05 18:32
1.写个jsp页面,里面用一个
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!