日期:2014-05-19  浏览次数:21058 次

*****100分******请问winform怎样自动显示最新纪录
*****100分******请问winform怎样自动显示最新纪录

------解决方案--------------------
timer_time()
{
this.filldate()
}
fillDate()
{
this.datatable=executesql( "select * from ........ ");

}

public static DataTable ExecuteSql(string sqlStr)
{
//throw new System.NotImplementedException();
DataTable dt = new DataTable();
SqlDataAdapter adapter = new SqlDataAdapter(sqlStr, cnn);
try
{
if (cnn.State == ConnectionState.Open)
{
cnn.Close();
}
cnn.Open();
adapter.Fill(dt);
}
catch (Exception ex)
{
throw new Exception( "数据读取出错! ", ex);
}
finally
{
cnn.Close();
}
return dt;
}
------解决方案--------------------

用Timer控件来实现自动刷新数据,显示最新纪录...
如下:
private void timer_Tick(object sender, EventArgs e)
{
RefData();
}

private void RefData()
{
this.Cursor = Cursors.WaitCursor;

DataTable dtData = new DataTable();

// 获取最新数据
dtData = FunRule.GetData();

// 显示
dataGridView.DataSource = dtData ;

this.Cursor = Cursors.Default;
}