How do you override the TableAdapter method on a table in a DataSet?

I currently have one declared DataSet that contains 3 tables. For this example, we'll call them User, Question, and Answer.

On each one I have a TableAdapter with different required methods i.e. GetData (), Update (), Delete (), etc.

In the response table, I would like to override the Update method from the TableAdapter to add some parameters that are not part of the table, but I need to go through due to the ObjectDataSource requirement.

How do I override the Update () method in the Response Table?

When trying to keep the project simple, I don't want to create a separate DAL layer.

+2


source to share


1 answer


Any designer created a class TableAdapter

of its respective members that are marked as virtual, include methods Update

and Fill

among others. Hemce, the solution simply inherits from the class created by the constructor TableAdapter

and overrides the method Update

, adding your own code there.

You also have the option to overload the method Update

if you want to change the method signature (number of parameters / types). You can do this either in a derived class, or, more conveniently, in my opinion, using an extension method:



public static void Update(this MyTableAdapter tableAdapter, ... other params ...)
{
    // do stuff here
    tableAdapter.Update(...);
}

      

+3


source







All Articles