DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: DataAdapter RowUpdated Event Problem (C# 2.0)

  1. #1
    Join Date
    Dec 2004

    Question DataAdapter RowUpdated Event Problem (C# 2.0)

    Hi guys,

    I have TableAdapters that is all are generated by .NET every time i drag & drop from DataSet in design view.

    Greatly .NET 2.0 can have partial classes, so i can take that opportunity to create many overloading as i can without changing the codes that is generated by .NET.

    Now these are my problems:
    Because TableAdapter that is generated by .NET is the front end of DataAdapter so i can not directly manipulating the DataAdapter.
    I want to add event handler for RowUpdating and RowUpdated event for the TableAdapter because _adapter field is private and Adapter property is also private. Both fields are SqlDataAdapter that are encapsulated by generated code and i don't want to break the encapsulation by making the Adapter property public.

    I hope you'll understand what i mean, TableAdapter is a user-defined class that is generated by .NET. In the TableAdapter, there are private _adapter field and private Adapter property. Both are generated too and their are the bridge for the SqlDataAdapter.

    The generated codes is in the file that has .designer.cs extension, i can create many new codes in the .cs extension. Example: DataSet1.designer.cs is the file that is generated by .NET and .NET don't want us to change the inside codes, so .NET 2.0 came with new partial syntax, and i can make many new file that has .cs extension as long all the classes inside the files are partial class, so they'll work together (they'll compiled into one class), that is the code-beside solution from .NET 2.0.

    Well I know most of you already know about partial syntax, i'm just hoping that you'll understand what i'm tryin to do.
    // these codes are inside the .cs extension
    public partial class TableAdapter1 {
         // RowUpdate events
         public event SqlRowUpdatingEventHandler RowUpdating;
         public event SqlRowUpdatedEventHandler RowUpdated;
         // i made an dummy overloading contructor because 
         // i dont want to change the generated codes by .NET
         public TableAdapter1(bool withRowUpdateEvents) {
              // these three functions are generated functions
              // i call them first because the _adapter is null
              // these are the event maker from the _adapter
              this._adapter.RowUpdating += new SqlRowUpdatingEventHandler(_adapter_RowUpdating);
              this._adapter.RowUpdated += new SqlRowUpdatedEventHandler(_adapter_RowUpdated);
          // these are the event handlers
          private void _adapter_RowUpdating(object sender, SqlRowUpdatingEventArgs e) {
               // by calling this i can catch the event
               this.RowUpdating(sender, e);
          private void _adapter_RowUpdated(object sender, SqlRowUpdatedEventArgs e) {
                // by calling this i can catch the event
               this.RowUpdated(sender, e);
    Now if you already have understood what i mean, what i'm tryin to do is just re-raise the RowUpdate events so i can catch the event from outside without break the encapsulation.
    // i could catch the event in any of my projects
    public partial class Project1 {
         TableAdapter1 tableAdapter1 = new TableAdapter1(true);
         public Project1() {
               tableAdapter1.RowUpdating += SqlRowUpdatingEventHandler(tableAdapter1 _RowUpdating);
               tableAdapter1.RowUpdated += SqlRowUpdatingEventHandler(tableAdapter1 _RowUpdated);
         private void tableAdapter1_RowUpdating(object sender, SqlRowUpdatingEventArgs e) {
                // some codes
         private void tableAdapter1_RowUpdated(object sender, SqlRowUpdatedEventArgs e) {
                // some codes
    Now every time i call the Update function from tableAdapter1 it will raise both the RowUpdating and RowUpdated event.

    The problem is when inside the RowUpdated event. In that event a NullReferenceException is raised. I don't know where, when, why the exception is raised.

    Thanks in advance.


  2. #2
    Join Date
    Dec 2004


    Sorry guys,

    The problems is solved. None of my code above is the NullReferenceException maker. In my project there were two comboBox that is bound to the same datasource but different in selectedValue's databinding. Because they were bound to the same datasource, every time i change one of the comboBox value than the second one will have the same value. But that is not the situation that i wanted. Well that problem is solved by making both of the comboBox bound to different reference.

    My RowUpdated event problem is solved but with some question in my head. The RowUpdated is raised, that means the update is succeed. If there were any field that is required like not allow null field, then it should raises the SqlException. Because both of the comboBox is bound to the field that doesn't allow null field. So why the NullReferenceException is raised? Because when i check to my SQL Server the inserted row is there.

    Well, at least the problem is solved.

Similar Threads

  1. Reliability Problem
    By elise in forum .NET
    Replies: 0
    Last Post: 10-30-2002, 05:39 AM
  2. COM event problem
    By Hari in forum Enterprise
    Replies: 0
    Last Post: 08-12-2002, 11:38 PM
  3. Exchange 2000 event handling problem
    By csaba in forum Enterprise
    Replies: 0
    Last Post: 03-13-2002, 12:35 PM
  4. Event Problem in BEAN
    By T.Oros in forum Java
    Replies: 0
    Last Post: 01-14-2001, 10:55 AM
  5. Problem to use Oracle 8.0.5 wtih MTS 2.0
    By Antonio Paglia in forum Enterprise
    Replies: 0
    Last Post: 04-03-2000, 10:02 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center