Can't pass TableAdapter as argument

Can't pass TableAdapter as argument

In VB6 it was easy to build my own datalayer.  In vb.net 2003 it was difficult, not nearly as time saving as in vb6.  I was hoping vb.net 2005 would be easier.

In many forms I fill table adapters, hardly a big surprise.  I was hoping to create procedures in a class that I could call from each form.  Unfortunately, I can pass a dataset, but I can't pass a TableAdapter.  When I try I get the message "Type 'TableAdapter' is not defined"

Ah, Shucks!

Is there a workaround

dennist



Answer this question

Can't pass TableAdapter as argument

  • mmoeser

    Hi,


    As I see it, tableadapters are just being derrived in the System.ComponentModel.Component Object. There's no TableAdapter Class...

    Although, you could use your own tableadapter as a parameter by specifying your name for your table adapter... eg.

    db1DataSetTableAdapters is your dataset name...
    Table1TableAdapter is your tableadapter name...

    private sub myFunc(ta As DataBinding.db1DataSetTableAdapters.Table1TableAdapter)

    but since you want a generic one you could either use System.Object or System.ComponentModel.Component as your parameter and cast it later....
    eg...

    private sub myFunc(ta As System.ComponentModel.Component) 
          Dim obj as Table1TableAdapter
          
          obj = (Table1TableAdapter) ta
          ''do something with obj...
    end sub



    cheers,


    Paul June A. Domag

  • Terry19692000

    Hi Dennis,
    While we don't have a base class specific to TableAdapters, you can create your own base class and tell the DataSet Designer to generate TableAdapters based on your base.
    To do this, simply create your own base class that derives from Component.  Build the project, then in the DataSet designer select the TableAdapter.  In the propety grid choose the property for BaseClass and type in your base class name.  Visual Studio will now generate TableAdapters based on your class and you can then pass them as a parameter.
    Steve Lasker
    Program Manager
    Visual Studio Data Designtime
    blogs.msdn.com/smartclientdata



  • NIck Chance

    Thanks, Steve

    I'll try to apply it tomorrow or the next day.  Undoubtedly I'll need to ask for more details.  I thank you very much for the response.

    dennist

  • Gustavo Carrazoni

    See the thread TableAdapters BaseClass.

    While you can change the baseclass the codegenerator uses, and that will allow you to receive an instance of those TableAdapters, those instances are casted as your base class and you won't be able to access any of the actual methods or properties of the actual TableAdapter (e.g. Connection), since your base class doesn't have access to the *derived* properties and methods that the codegenerator creates.

    There's however a work-around for that as provided by Aquilax, that involves manually creating partial classes for each TableAdapter.

    Regards,
    Juan

  • Can't pass TableAdapter as argument