none
Getting the dataset to raise an event? RRS feed

  • Question

  • I’m creating a windows forms application that uses as dataset to store information retrieved from a web service. In typical newbie style I’m beginning to realise that as my application grows I’ve probably not gone about things the right way.

     

    The problem is the dataset will update with information from the web service in a random fashion and depending on the values returned, I want to do a number of things with it. If the values returned haven’t changed I don’t need to do anything. At the moment I created a procedure that loops through each row in the dataset to see if the values have changed, then takes the appropriate action if they have.

     

    Is it possible to have things work the other way around – meaning when the values in the dataset change they ‘notify’ a procedure which then takes any actions needed (if any). So instead of having to check the dataset on a regular basis I can forget about it and let it do the notifying for me ?

    Thursday, August 13, 2009 2:11 PM

Answers

  • Add an event handler to the ColumnChanging event in each data table. There are many other events to track as well.

    // add when you create your tables 1 for each data table
    yourTable.ColumnChanging += new DataColumnChangeEventHandler(Column_Changing );


    // your event handler
    private static void Column_Changing(object sender, DataColumnChangeEventArgs e )
    {
       // do something
    }


    http://msdn.microsoft.com/en-us/library/system.data.datatable_members(VS.71).aspx

    See the events part.
    • Marked as answer by Beanze Thursday, August 13, 2009 3:17 PM
    Thursday, August 13, 2009 3:05 PM

All replies

  • The DataTable objects have events that track row and column changes and others. The DataSet object only has 3 events and none track data changes within tables.
    Thursday, August 13, 2009 2:40 PM
  • Sorry, wrong terminology - my DataSet contains 3 DataTables so that is what I meant. How do I go about raising an event if the value in one column of a DataTable is changed?
    Thursday, August 13, 2009 2:59 PM
  • Add an event handler to the ColumnChanging event in each data table. There are many other events to track as well.

    // add when you create your tables 1 for each data table
    yourTable.ColumnChanging += new DataColumnChangeEventHandler(Column_Changing );


    // your event handler
    private static void Column_Changing(object sender, DataColumnChangeEventArgs e )
    {
       // do something
    }


    http://msdn.microsoft.com/en-us/library/system.data.datatable_members(VS.71).aspx

    See the events part.
    • Marked as answer by Beanze Thursday, August 13, 2009 3:17 PM
    Thursday, August 13, 2009 3:05 PM
  • Nice one - thanks for your help
    Thursday, August 13, 2009 3:17 PM
  • You're welcome.
    Thursday, August 13, 2009 3:21 PM