Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
|
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 25th, 2007, 01:19 AM
Authorized User
 
Join Date: Aug 2005
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Default dataset and sql query notification

Hi all;
how to refresh the dataset and reflect the changes on page using sql2005 query notification.
I can get the event of change in database in the code behind.
but i'm not getting a way to reflect the changes in current dataset and display new changes on page.


 delegate void UIDelegate();

    protected void Page_Load(object sender, EventArgs e)
    {
        string connstring = "Server=work02025;User ID=sa;pwd=sa;database=Portal";
        SqlConnection SQLConnectionObject = new SqlConnection(connstring);
        SqlCommand cmd = new SqlCommand("SELECT EmpID, FName, " +
            "Address FROM dbo.EmployeeMaster", SQLConnectionObject);

        SqlDependency depend = new SqlDependency(cmd);
        SqlDependency.Start(connstring);
        depend.OnChange += new OnChangeEventHandler(MyOnChanged);

        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        da.Fill(ds);


        Cache.Insert("MyDataSet", ds);
        GridView1.DataSource = ds;
        GridView1.DataBind();


    }

    private void MyOnChanged(object sender, SqlNotificationEventArgs e)
    {
        try
        {
            //to test place a break point here
            //and change any data in the specified table
            string msg = "Notified";

            UIDelegate uidel = new UIDelegate(RefreshData);
           // this..Invoke(uidel, null);
            uidel.Invoke();

            //Remove the handler as it is used for a single notification.
            SqlDependency dependency = (SqlDependency)sender;
            dependency.OnChange -= MyOnChanged;
            //RefreshData();


        }
        catch (Exception ex)
        {
           // Response.Write(ex.Message);
        }
    }

private void RefreshData()
    {
        // Since the code is executing on the UI thread,it is safe to update the UI.

        Label1.Text = "Database had some changes and are applied in the Grid";

        GridView1.DataSource = null;
        GridView1.DataBind();

        // Reload the dataset that is bound to the grid.
       // GetAdvtData();
    }


this is the test code.
after first page load, if there is change in database then it goes to "MyOnChanged"
but even if Label1.Text has been changed there, it doesn't appear on page!!!!

any solution?

 
Old September 26th, 2007, 07:22 PM
Registered User
 
Join Date: Sep 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi there, did u find any solution to your problem? I am also in an exact same situation where I cannot update the GUI contents although I am able to receive updated data using Query notification. I am using ASP.NET 2.0. If you have any solution, please share it with me. Thanks in advance
Kona






Similar Threads
Thread Thread Starter Forum Replies Last Post
How can i use typed dataset with Join Sql query? vijaykumartaduri BOOK: Professional Crystal Reports for VS.NET 0 November 10th, 2005 04:02 AM
query of dataset jjdunkel ASP.NET 1.0 and 1.1 Professional 7 July 28th, 2004 08:28 AM
Re: SQL Server dataset to ACCESS dataset dazzer ADO.NET 0 March 22nd, 2004 05:28 AM
SQL Errors - ASP Notification mindyjeanne All Other Wrox Books 0 September 27th, 2003 04:48 PM
Mail Notification in MS SQL Server Kilian SQL Server 2000 0 July 9th, 2003 09:20 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.