大众信息网

如何将数据库查询的内容在一个页面表格中显示

关注:233  答案:2  手机版
解决时间 2021-03-06 09:01
如何将数据库查询的内容在一个页面表格中显示
最佳答案
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);
全部回答
1.写个jsp页面,里面用一个
提交你的action 2.在后台的action中根据jsp发出的命令搜索数据库,并将数据保存到相应的集合中 3.从集合中取得数据,在jsp页面显示
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!