如何在Chart中显示最新值?

时间:2014-09-24 05:33:57

标签: c# sql asp.net database charts

我必须动态显示与db连接的图表。它工作正常。代码如下。但我的问题是我的数据库每5分钟自动更新一次。所以我必须显示最新插入信息的图表。请帮我。 代码如下:

public partial class chartDummy : System.Web.UI.Page
{
    SqlConnection con;
    SqlCommand cmd;
    SqlDataAdapter da;
    DataSet ds;

    protected void Page_Load(object sender, EventArgs e)
    {
        con = new SqlConnection(@"ConnectionString");
        cmd = new SqlCommand("Select Mains_Run_Hrs, DG_Run_Auto_Mode, Battery_Run_Hrs, Solar_Run_hrs from tbl_runtime_report", con);
        da = new SqlDataAdapter(cmd);
        ds = new DataSet();
        da.Fill(ds);
        DataView source = new DataView(ds.Tables[0]);
            Chart1.DataSource = ds;
            Chart1.Series[0].YValueMembers = "Mains_Run_Hrs";
            Chart1.Series[0].XValueMember = "DG_Run_Auto_Mode";
            Chart1.Series[0].XValueMember = "Battery_Run_Hrs";
            Chart1.Series[0].XValueMember = "Solar_Run_hrs";
            Chart1.DataBind();

    }   
}

1 个答案:

答案 0 :(得分:0)

  cmd = new SqlCommand("Select Mains_Run_Hrs, DG_Run_Auto_Mode, Battery_Run_Hrs, Solar_Run_hrs from tbl_runtime_report ORDER BY Site_ID DESC", con);