Can this be made generic?

  • Thread starter Thread starter John
  • Start date Start date
J

John

Hi

I have below code which updates table tblClients and handles concurrency
violation if needed. Is there a way to make the code generic so for example
another table's name can be passed to the SUB?

Thanks

Regards


Private Sub UpdateDatabase()

Try
Me.tblClientsTableAdapter.Update(Me.ContactsDataSet.tblClients)

Catch dbcx As Data.DBConcurrencyException
HanldeConcurrency(dbcx.Row, ContactsDataSet.tblClientsRow)

End Try

End Sub
 
Hi John,

Probably not, at least not without significant changes. The problem you have
is knowing the tblClients and tblClientsRow parts. You could use strings
there, such as theDataset.Tables("tblClientsRow"), or alternatively you
could use an interface but that would probably be just shifting the code
writing around, not reducing or re-using that much .
 
I have below code which updates table tblClients and handles concurrency
violation if needed. Is there a way to make the code generic so for
example another table's name can be passed to the SUB?

I don't know whether anyone from Microsoft regularly reads the Visual Basic
groups but if they do then I am very surprised that they permit one of their
own MVPs to engage in such outrageous long term trolling activities in one
of their own public newsgroups, such as the activity that the person who
purports to be Bill McCarthy has engaged in on the
microsoft.public.vb.general.discussion group for many months. If this man
belongs to you:

https://mvp.support.microsoft.com/profile=B2D0BB02-3E35-4293-B4B9-25680609CCB8

.. . . then perhaps you might like to look at his activity in that group.
Here for example is one of his very latest offerings:
 
Hi Bill

Thanks. I'll take what I can get :)

So Dataset.Tables("tblClientsRow") is the equivalent of tblClientsRow, what
is the "string" equivalents of tblClientsTableAdapter and tblClients?

Many thanks again.

Regards
 
Hmm... I don't know of any way to get the tableadapter, nor to generalize
it. You could add a partial class for each table adapter and an interface,
and use that interface.



Private Sub UpdateDatabase(adapter As DataAdapter)
 
Yeh, the difficulty though is with the TableAdapter. You'd could resort to
a late bound call (or reflection), otherwise the only thing I can think of
is partial classes for each adapter, adding an Interface that has Update
etc.
 
Back
Top