它无法正常工作.它给出了错误 [英] It's not working Properly.it gives error
本文介绍了它无法正常工作.它给出了错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
static int i;
DataTable dt;
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(@"Data Source=.;Initial Catalog=ri;User ID=sa;Password=pass");
string s = "select name from ajax";
SqlDataAdapter ad = new SqlDataAdapter(s, con);
//DataSet ds = new DataSet();
dt = new DataTable();
ad.Fill(dt);
ad.Dispose();
ad = null;
}
protected void Timer1_Tick(object sender, EventArgs e)
{
if (i < dt.Rows.Count)
{
foreach (DataColumn c in dt.Columns)
{
Label1.Text = dt.Rows[i][c].ToString();
}
i++;
}
else
{
i = 0;
}
}
推荐答案
很难知道问题所在,而又不会被告知更多信息,但是我怀疑您的标签永远不会显示数据的最后一行.
尝试使用:
It''s difficult to work out what the problem is, without being told rather more information, but I suspect that your label only ever shows the final row of the data.
Try using:
Label1.Text += dt.Rows[i][c].ToString();
.还是更好,请使用StringBuilder!
Instead. Or better still, use a StringBuilder!
这篇关于它无法正常工作.它给出了错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文