PC Review


Reply
Thread Tools Rate Thread

Can this be made generic?

 
 
John
Guest
Posts: n/a
 
      26th Apr 2008
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
 
 
 
 
Bill McCarthy
Guest
Posts: n/a
 
      26th Apr 2008
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" <(E-Mail Removed)> wrote in message
news:%23G1%(E-Mail Removed)...
> 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
 
Mike Williams
Guest
Posts: n/a
 
      26th Apr 2008
"John" <(E-Mail Removed)> wrote in message
news:%23G1%(E-Mail Removed)...


> 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/pr...9-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" <(E-Mail Removed)> wrote in message
news:19A5DEEA-ED6A-4721-9DB9-(E-Mail Removed)...

> 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
 
John
Guest
Posts: n/a
 
      26th Apr 2008
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" <(E-Mail Removed)> wrote in message
news:F74696A3-7F8F-4B46-B3D8-(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:%23G1%(E-Mail Removed)...
>> 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
 
Bill McCarthy
Guest
Posts: n/a
 
      26th Apr 2008

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" <(E-Mail Removed)> wrote in message
news:eyNPZ%(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:F74696A3-7F8F-4B46-B3D8-(E-Mail Removed)...
>> 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" <(E-Mail Removed)> wrote in message
>> news:%23G1%(E-Mail Removed)...
>>> 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
 
Bill McCarthy
Guest
Posts: n/a
 
      26th Apr 2008
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" <(E-Mail Removed)> wrote in message
news:_(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
>> news:F74696A3-7F8F-4B46-B3D8-(E-Mail Removed)...
>>> 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" <(E-Mail Removed)> wrote in message
>>> news:%23G1%(E-Mail Removed)...
>>>> 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
 
Cor Ligthert[MVP]
Guest
Posts: n/a
 
      27th Apr 2008
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" <(E-Mail Removed)> schreef in bericht
news:%23G1%(E-Mail Removed)...
> 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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can this be made generic? John Microsoft ADO .NET 6 27th Apr 2008 05:56 AM
Generics Question - how to implement a method on a generic thatreturns the same type as the generic IUnknown Microsoft C# .NET 0 20th Mar 2008 06:34 PM
Copy Items from a Generic List into multiple Generic Lists Sam Shrefler Microsoft C# .NET 5 12th Oct 2007 06:27 PM
error C2955: 'Vector' : use of class generic requires generic argument list Herby Microsoft VC .NET 5 14th Mar 2006 03:55 PM
Can probing path be made generic? Jack Wright Microsoft ASP .NET 0 9th Mar 2004 07:00 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:05 PM.