asp.net中的timer控件
下面这段代码运行不了,编译时指出的错误是:非静态的字段、方法或属性“_default.aspx.cs”要求对象引用引用。表示错误的指针指向的是“ while (sdd.Read()){
TextBox1.Text += sdd["name"] + "在" + sdd["time"] + "时说到:" + '\n' + sdd["word"] + '\n';
max1 += 1;
}”中的TextBox1.Text。请问怎么解决呢?(TextBox1是页面上的一个文本框)
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Timers;
public partial class _Default : System.Web.UI.Page
{
private int i ;
private string str=String.Empty;
private static int max1;
private static void OnTimedEvent(object source, System.Timers.ElapsedEventArgs e)
{
SqlConnection h = new SqlConnection();
h.ConnectionString = "Data Source=20101010-2103;Initial Catalog=chat1;Integrated Security=True";
h.Open();
SqlCommand cmd3 = new SqlCommand("select * from liaotian where id>max1", h);
SqlDataReader sdd = cmd3.ExecuteReader();
while (sdd.Read())
{
TextBox1.Text += sdd["name"] + "在" + sdd["time"] + "时说到:" + '\n' + sdd["word"] + '\n';
max1 += 1;
}
}
protected void Page_Load(object sender, EventArgs e)
{
int max = 0; int j;
SqlConnection f = new SqlConnection();
f.ConnectionString = "Data Source=20101010-2103;Initial Catalog=chat1;Integrated Security=True";
f.Open();
SqlCommand cmd1 = new SqlCommand("select * from liaotian", f);
SqlDataReader sd = cmd1.ExecuteReader();
while (sd.Read())
{Response.Write(sd["id"]);
TextBox1.Text += sd["name"] + "在" + sd["time"] + "时说到:" + '\n' + sd["word"]+'\n';
}
f.Close();
SqlConnection d = new SqlConnection();
d.ConnectionString = "Data Source=20101010-2103;Initial Catalog=chat1;Integrated Security=True";
d.Open();
SqlCommand cmd = new SqlCommand("select * from liaotian", d);
SqlDataReader sdr = cmd.ExecuteReader();
while (sdr.Read())
{
j = Convert.ToInt32(sdr["id"]);
if (max < j)
max =Convert.ToInt32( sdr["id"]);
}
i = max+1;
d.Close();
max1 = i-1;
System.Timers.Timer myTimer = new System.Timers.Timer();
myTimer.Elapsed += new System.Timers.ElapsedEventHandler(OnTimedEvent);
myTimer.Interval = 500;
myTimer.Enabled = true;
}
--------------------编程问答-------------------- SqlCommand cmd3 = new SqlCommand("select * from liaotian where id>"+max1, h);
SqlDataReader sdd = cmd3.ExecuteReader();
while (sdd.Read())
{
TextBox1.Text += sdd["name"] + "在" + sdd["time"] + "时说到:" + "\n" + sdd["word"] + "\n";
}
--------------------编程问答-------------------- 是TextBox1的问题
补充:.NET技术 , ASP.NET