0

我正在为我的fyp.

我用来SqlDependency从缓存中获取表更改信息。

我使用了SqlDataAdapter,dataSet和 gridview,但它没有在屏幕上显示任何结果。

你能告诉我代码中的问题出在哪里吗?

protected void refresh_Click(object sender, EventArgs e)
{
        if (Cache["shipOrders"] == null)
        {
            gvshipOrders.DataSource = Cache["shipOrders"];
            gvshipOrders.DataBind();
            lblOrderNotification.Text = "last order recived at " + DateTime.Now.ToString();
        }
        else
        {

            string xconnectionString = ConfigurationManager.ConnectionStrings["LGDB"].ToString();
            SqlConnection sqlCon = new SqlConnection(xconnectionString);
            SqlDataAdapter da = new SqlDataAdapter("viewOrders", sqlCon);
            DataSet ds = new DataSet();
            da.Fill(ds);
            SqlCacheDependency XsqlcacheDependecy = new SqlCacheDependency("secaloTest1", "customerShipOrder");
            //caching shipOrders table data
            /*
            Cache.Insert("shipOrders", ds, null, DateTime.Now.AddSeconds(60), Cache.NoSlidingExpiration, CacheItemPriority.Default, null);
            another overloaded method is used */
            Cache.Insert("shipOrders", ds, XsqlcacheDependecy); 
            gvshipOrders.DataSource = ds;
            gvshipOrders.DataBind();
            lblOrderNotification.Text = "orders retrived from database at " + DateTime.Now.ToString();
        }
    }
4

1 回答 1

0

我发现了问题,

 public partial class OrderProccessing : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["email"] == null)
        {
            Response.Redirect("Default.aspx");
        }
        else
        {
            string value = Session["email"].ToString();
            Classes.AddAddress addcuid = new Classes.AddAddress(value);
            txtstaffname.Text = addcuid.addStaffName().ToString();
            txtstaffID.Text = addcuid.fetchStaffID().ToString();
        }
    }
    protected void refresh_Click(object sender, EventArgs e)
    {
        if (Cache["shipOrders"] != null)
        {
            myGrid.DataSource = Cache["ShipOrders"];                      
            myGrid.DataBind();
            lblOrderNotification.Text = "last order recived at " + DateTime.Now.ToString();
        }
        else
        {
            string xconnectionString = ConfigurationManager.ConnectionStrings["LGDB"].ToString();
            SqlConnection sqlCon = new SqlConnection(xconnectionString);
            SqlDataAdapter da = new SqlDataAdapter("viewOrders", sqlCon);
            da.SelectCommand.CommandType = CommandType.StoredProcedure;
            DataSet ds = new DataSet();
            da.Fill(ds);
            SqlCacheDependency XsqlcacheDependecy = new SqlCacheDependency("secaloTest1", "customerShipOrder");
            //caching shipOrders table data
            /*
            Cache.Insert("shipOrders", ds, null, DateTime.Now.AddSeconds(60), Cache.NoSlidingExpiration, CacheItemPriority.Default, null);
            another overloaded method is used */
            Cache.Insert("shipOrders", ds, XsqlcacheDependecy);                            
            myGrid.DataSource = ds;               
            myGrid.DataBind();
            lblOrderNotification.Text = "orders retrived from database at " + DateTime.Now.ToString();
        }
    }
}
于 2013-07-20T11:09:33.617 回答