About new TABLEADAPTERS in VS2005 ***URGENT**

I have a generic subrutine that saves the data and one parameter is a DataAdapter as Dataadapter.
[code]
Public Sub SaveTableChanges(ByVal dtDataTable As DataTable, _
ByVal daDataAdapter As SqlClient.SqlDataAdapter, _
ByVal drDataRowState As DataRowState)

SaveTableChanges(dtCompanies, daCompanies, DataRowState.Added)
SaveTableChanges(dtCompPriceList, daCompPriceList, DataRowState.Added)
[/code]
Now I am trying to find how to declare a parameter in the Sub SaveTableChanges in order to accept all the TableAdapters eg
[code]
SaveTableChanges(DataTableCompanies, TableAdapterCompanies, DataRowState.Added)
SaveTableChanges(DataTablePhones, TableAdapterPhones, DataRowState.Added)
[/code]

Is there any other way in order to use the subroutine
Thanks


Answer this question

About new TABLEADAPTERS in VS2005 ***URGENT**

  • PrashaG

    If they are not SqlDataAdapters, what are they Just figure out what their common root class or interface is and use that (e.g. DbDataAdapter or IDbDataAdapter). If they dont have a common base class that implements an Update method, you wont be able to create a single method that can be used on all forms.

  • michael_he

    No my friend. It seems that I didn't make clear my problem. In VS2003 I had:

    [code]
    Public Sub SaveTableChanges(ByVal dtDataTable As DataTable, _
    ByVal daDataAdapter As SqlClient.SqlDataAdapter, _
    ByVal drDataRowState As DataRowState)

    SaveTableChanges(dtCompanies, daCompanies, DataRowState.Added)
    SaveTableChanges(dtCompPriceList, daCompPriceList, DataRowState.Added)
    [/code]
    and it is working perfect.

    In VS2005 I am havling:

    [code]
    Public Sub SaveTableChanges(ByVal dtDataTable As DataTable, _
    ByVal daDataAdapter As SqlClient.SqlDataAdapter, _
    ByVal drDataRowState As DataRowState

    SaveTableChanges(DataTableCompanies, TableAdapterCompanies, DataRowState.Added)
    SaveTableChanges(DataTablePhones, TableAdapterPhones, DataRowState.Added)
    [/code]
    Because TableAdapterCompanies or TableAdapterPhones are not SqlClient.SqlDataAdapter. What I want is a common procedure for all my forms with which I will save my data. Here is my old one (VS2003):

    Public Sub SaveTableChanges(ByVal dataTable As DataTable, _

    ByVal dataAdapter As SqlClient.SqlDataAdapter, _

    ByVal dataRowState As DataRowState)

    'Try

    Dim DataChanges As DataTable

    Dim RecChanged As Integer = 0

    DataChanges = dataTable.GetChanges(dataRowState)

    If Not (DataChanges Is Nothing) Then

    RecChanged = dataAdapter.Update(dataTable)

    If dataRowState = dataRowState.Added Then

    My.Settings.strMessage = My.Settings.strMessage & " - Additions: " & RecChanged

    ElseIf dataRowState = dataRowState.Modified Then

    My.Settings.strMessage = My.Settings.strMessage & " - Changes: " & RecChanged

    ElseIf dataRowState = dataRowState.Deleted Then

    My.Settings.strMessage = My.Settings.strMessage & " - Deletions: " & RecChanged

    End If

    End If

    'Catch ex As Exception

    'Manipulation of the errors...

    UnhandledExceptionHandler(ex)

    End Try '

    End Sub

    Thanks in advance


  • MBoy

    TableAdapters do not have a common base class or interface. The main feature is TableAdapters are meant to be abstractions, not inherit DataAdapters. You can add your own interface using partial classes which can then delegate to the TableAdapter.Update method.



  • jwp118

    Thanks Steve, can you give me an example

    Thanks in advance.


  • Orschiedt

    Not clear on the problem here. Seems like you have exactly what you need. Just call the method as many times as necessary.
  • Mike1234

    If you make a master-detail form through the IDE of VS2005 (meaning no code from you) with SQL server 2005 express, it will use the TableAdapters (the new class). So when you will try to use my procedure the error will be:

    Value of type "Lings2006.DataSetLings2006TableAdapters.CompaniesTableAdapter" cannot be converted to "System.Data.SqlClient.SqlDataAdapter".

    I hope that this will help you to understand my problem.

    Thanks in advance.


  • About new TABLEADAPTERS in VS2005 ***URGENT**