这个循环读数据的,太给劲了,调半谈,他只能读出最后一条,大家帮我看看,怎么改呀?
让他读出一条写一个text里.读一个写一个..不要光把最后一个读出来写进入,,有什么好办法吗?在线等!!!string str = "select bbsid,bbsname,bbscontext,bbsdate from bbs order by bbsid desc";
OleDbConnection cn = null;
OleDbDataReader dr = DAOHelper.ExecuteReader(str,ref cn);
while(dr.Read())
{
this.index.Text = dr["bbsid"].ToString();
this.context.Text = dr["bbscontext"].ToString();
this.bbsname.Text = dr["bbsname"].ToString();
this.bbsdate.Text = dr["bbsdate"].ToString();
i++;
}
dr.Close();cn.Close();cn.Dispose();
if(i==0)
{
this.context.Text = "当前没有公告内容";
}
让他读出一条写一个text里.读一个写一个..不要光把最后一个读出来写进入,,有什么好办法吗?在线等!!!string str = "select bbsid,bbsname,bbscontext,bbsdate from bbs order by bbsid desc";
OleDbConnection cn = null;
OleDbDataReader dr = DAOHelper.ExecuteReader(str,ref cn);
while(dr.Read())
{
this.index.Text = dr["bbsid"].ToString();
this.context.Text = dr["bbscontext"].ToString();
this.bbsname.Text = dr["bbsname"].ToString();
this.bbsdate.Text = dr["bbsdate"].ToString();
i++;
}
dr.Close();cn.Close();cn.Dispose();
if(i==0)
{
this.context.Text = "当前没有公告内容";
}
可以用字符串连接起来啊.......
while(dr.Read())
{
}
里的所有“=”改成“+=”
while(dr.Read())
{
this.index.Text += dr["bbsid"].ToString();
this.context.Text += dr["bbscontext"].ToString();
this.bbsname.Text += dr["bbsname"].ToString();
this.bbsdate.Text += dr["bbsdate"].ToString();
i++;
}
string s1 = "test1,";
s1 += "test2 "; //s1的内容为"test1,test2"
s1 = "test2"; //s1的内容为"test2"s1 += "test2 "; 相当于
s1 = s1 + "test2";
OleDbDataReader dr = DAOHelper.ExecuteReader(str,ref cn);
while(dr.Read())
{
backid += dr["bbsid"].ToString();
backcontext += dr["bbscontext"].ToString();
backname += dr["bbsname"].ToString();
backdate += dr["bbsdate"].ToString();
i++;
}
dr.Close();cn.Close();cn.Dispose();
if(i==0)
{
this.context.Text = "当前没有公告内容";
}
Response.Write("<table cellpadding=0 cellspacing=0 border=0 width=\"100%\">");
Response.Write("<tr><td width=\"50%\">");
Response.Write("当前编号:<asp:Label id=\"index\" runat=\"server\"></asp:Label></td>");
Response.Write("<td width=\"50%\"></td></tr>");
Response.Write("<tr><td colspan=2 width=\"100%\">");
Response.Write("<asp:Label id=context runat=server></asp:Label></td></tr>");
Response.Write("<tr><td width=\"50%\"");
Response.Write("作者:<asp:Label id=bbsname runat=server></asp:Label></td>");
Response.Write("<td width=\"50%\" align=center>");
Response.Write("留言日期:<asp:Label id=bbsdate runat=server></asp:Label></td></tr></table>");
this.index.Text = backid;
this.context.Text = backcontext;
this.bbsname.Text = backname;
this.bbsdate.Text = backdate;
我这样做不行啊...就是一个留言板似的东西~~~写一个TABLE把内容放进去,
然后在写一个TABLE,把内容在放进去
while(dr.Read())
{
Response.Write("<table cellpadding=0 cellspacing=0 border=0 width=\"100%\">");
Response.Write("<tr><td width=\"50%\">");
Response.Write("当前编号:</td>");
Response.Write("<td width=\"50%\">" + dr.GetString(0) + "</td></tr></table>");
}