PC Review Forums Newsgroups Microsoft DotNet Microsoft ADO .NET Can this be made generic?

Reply

Can this be made generic?

 
Thread Tools Rate Thread
Old 26-04-2008, 03:01 AM   #1
John
Guest
 
Posts: n/a
Default Can this be made generic?


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


  Reply With Quote
Old 26-04-2008, 04:34 AM   #2
Bill McCarthy
Guest
 
Posts: n/a
Default Re: Can this be made generic?

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 .




"John" <info@nospam.infovis.co.uk> wrote in message
news:%23G1%238F0pIHA.2636@TK2MSFTNGP04.phx.gbl...
> 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
>


  Reply With Quote
Old 26-04-2008, 09:38 AM   #3
Mike Williams
Guest
 
Posts: n/a
Default Re: Can this be made generic?

"John" <info@nospam.infovis.co.uk> wrote in message
news:%23G1%238F0pIHA.2636@TK2MSFTNGP04.phx.gbl...


> 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/p...B9-25680609CCB8

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

"Bill McCarthy" <Bill@N0SPAM.com> wrote in message
news:19A5DEEA-ED6A-4721-9DB9-9F5D8509D825@microsoft.com...

> Yeh, still a way to go. I think given the warm reaction today,
> and given some folks have learning difficulties around here
> (obviously why they are still *stuck* in VB6 *only*), might
> just have to ramp things up a notch or two, and make it more
> toasty




  Reply With Quote
Old 26-04-2008, 04:10 PM   #4
John
Guest
 
Posts: n/a
Default Re: Can this be made generic?

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

"Bill McCarthy" <Bill@N0SPAM.com> wrote in message
news:F74696A3-7F8F-4B46-B3D8-5505630C5E11@microsoft.com...
> 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 .
>
>
>
>
> "John" <info@nospam.infovis.co.uk> wrote in message
> news:%23G1%238F0pIHA.2636@TK2MSFTNGP04.phx.gbl...
>> 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
>>

>



  Reply With Quote
Old 26-04-2008, 04:41 PM   #5
Bill McCarthy
Guest
 
Posts: n/a
Default Re: Can this be made generic?


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)
>>>
>>> Try
>>> Me.tblClientsTableAdapter.Update(Me.ContactsDataSet.tblClients)
>>>
>>> Catch dbcx As Data.DBConcurrencyException
>>> HanldeConcurrency(dbcx.Row, ContactsDataSet.tblClientsRow)
>>>
>>> End Try
>>>
>>> End Sub





"John" <info@nospam.infovis.co.uk> wrote in message
news:eyNPZ%236pIHA.5096@TK2MSFTNGP02.phx.gbl...
> 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
>
> "Bill McCarthy" <Bill@N0SPAM.com> wrote in message
> news:F74696A3-7F8F-4B46-B3D8-5505630C5E11@microsoft.com...
>> 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 .
>>
>>
>>
>>
>> "John" <info@nospam.infovis.co.uk> wrote in message
>> news:%23G1%238F0pIHA.2636@TK2MSFTNGP04.phx.gbl...
>>> 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
>>>

>>

>
>


  Reply With Quote
Old 26-04-2008, 05:35 PM   #6
Bill McCarthy
Guest
 
Posts: n/a
Default Re: Can this be made generic?

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.


"Steve Gerrard" <mynamehere@comcast.net> wrote in message
news:_bydnWD6YNWjyo7VnZ2dnUVZ_tqtnZ2d@comcast.com...
> I'm not sure where the "tblClientsRow" came from, but theDataset.Tables is
> a collection of data tables. They are identified by the name used when
> they were added to the dataset, usually based on the source of the data,
> or a name assigned explicitly when the table was added.
>
> If you have a string table name, you can get at any table using
> theDataset.Tables("theTableName").
>
>
> John wrote:
>> 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
>>
>> "Bill McCarthy" <Bill@N0SPAM.com> wrote in message
>> news:F74696A3-7F8F-4B46-B3D8-5505630C5E11@microsoft.com...
>>> 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 . "John" <info@nospam.infovis.co.uk> wrote in message
>>> news:%23G1%238F0pIHA.2636@TK2MSFTNGP04.phx.gbl...
>>>> 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

>
>


  Reply With Quote
Old 27-04-2008, 05:56 AM   #7
Cor Ligthert[MVP]
Guest
 
Posts: n/a
Default Re: Can this be made generic?

John,

The Row that creates an error is marked in its rowerror property, this is a
string which describes the error.

It is should for anybody be easy to find that row and take the actions on
that.

http://msdn2.microsoft.com/en-us/library/system.data.datarow.rowerror(VS.71).aspx

Cor


"John" <info@nospam.infovis.co.uk> schreef in bericht
news:%23G1%238F0pIHA.2636@TK2MSFTNGP04.phx.gbl...
> 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
>


  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off