Can this be made generic?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • John

    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.tblClientsTa bleAdapter.Upda te(Me.ContactsD ataSet.tblClien ts)

    Catch dbcx As Data.DBConcurre ncyException
    HanldeConcurren cy(dbcx.Row, ContactsDataSet .tblClientsRow)

    End Try

    End Sub


  • Bill McCarthy

    #2
    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.Tabl es("tblClientsR ow"), 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.in fovis.co.ukwrot e in message
    news:%23G1%238F 0pIHA.2636@TK2M SFTNGP04.phx.gb l...
    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.tblClientsTa bleAdapter.Upda te(Me.ContactsD ataSet.tblClien ts)
    >
    Catch dbcx As Data.DBConcurre ncyException
    HanldeConcurren cy(dbcx.Row, ContactsDataSet .tblClientsRow)
    >
    End Try
    >
    End Sub
    >

    Comment

    • Mike Williams

      #3
      Re: Can this be made generic?

      "John" <info@nospam.in fovis.co.ukwrot e in message
      news:%23G1%238F 0pIHA.2636@TK2M SFTNGP04.phx.gb l...

      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.publi c.vb.general.di scussion group for many months. If this man
      belongs to you:



      .. . . 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.co mwrote in message
      news:19A5DEEA-ED6A-4721-9DB9-9F5D8509D825@mi crosoft.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 :D


      Comment

      • John

        #4
        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 tblClientsTable Adapter and tblClients?

        Many thanks again.

        Regards

        "Bill McCarthy" <Bill@N0SPAM.co mwrote in message
        news:F74696A3-7F8F-4B46-B3D8-5505630C5E11@mi crosoft.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.Tabl es("tblClientsR ow"), 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.in fovis.co.ukwrot e in message
        news:%23G1%238F 0pIHA.2636@TK2M SFTNGP04.phx.gb l...
        >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.tblClientsTa bleAdapter.Upda te(Me.ContactsD ataSet.tblClien ts)
        >>
        > Catch dbcx As Data.DBConcurre ncyException
        > HanldeConcurren cy(dbcx.Row, ContactsDataSet .tblClientsRow)
        >>
        > End Try
        >>
        >End Sub
        >>
        >

        Comment

        • Bill McCarthy

          #5
          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.tblClientsTa bleAdapter.Upda te(Me.ContactsD ataSet.tblClien ts)
          >>>
          >> Catch dbcx As Data.DBConcurre ncyException
          >> HanldeConcurren cy(dbcx.Row, ContactsDataSet .tblClientsRow)
          >>>
          >> End Try
          >>>
          >>End Sub



          "John" <info@nospam.in fovis.co.ukwrot e in message
          news:eyNPZ%236p IHA.5096@TK2MSF TNGP02.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 tblClientsTable Adapter and tblClients?
          >
          Many thanks again.
          >
          Regards
          >
          "Bill McCarthy" <Bill@N0SPAM.co mwrote in message
          news:F74696A3-7F8F-4B46-B3D8-5505630C5E11@mi crosoft.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.Tabl es("tblClientsR ow"), or
          >alternativel y 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.in fovis.co.ukwrot e in message
          >news:%23G1%238 F0pIHA.2636@TK2 MSFTNGP04.phx.g bl...
          >>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.tblClientsTa bleAdapter.Upda te(Me.ContactsD ataSet.tblClien ts)
          >>>
          >> Catch dbcx As Data.DBConcurre ncyException
          >> HanldeConcurren cy(dbcx.Row, ContactsDataSet .tblClientsRow)
          >>>
          >> End Try
          >>>
          >>End Sub
          >>>
          >>
          >
          >

          Comment

          • Steve Gerrard

            #6
            Re: Can this be made generic?

            I'm not sure where the "tblClients Row" came from, but theDataset.Tabl es 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.Tabl es("theTableNam e").


            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
            tblClientsTable Adapter and tblClients?
            Many thanks again.
            >
            Regards
            >
            "Bill McCarthy" <Bill@N0SPAM.co mwrote in message
            news:F74696A3-7F8F-4B46-B3D8-5505630C5E11@mi crosoft.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.Tabl es("tblClientsR ow"),
            >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.in fovis.co.ukwrot e in message
            >news:%23G1%238 F0pIHA.2636@TK2 MSFTNGP04.phx.g bl...
            >>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.tblClientsTa bleAdapter.Upda te(Me.ContactsD ataSet.tblClien ts)
            >>>
            >> Catch dbcx As Data.DBConcurre ncyException
            >> HanldeConcurren cy(dbcx.Row, ContactsDataSet .tblClientsRow)
            >>>
            >> End Try
            >>>
            >>End Sub

            Comment

            • Bill McCarthy

              #7
              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@com cast.netwrote in message
              news:_bydnWD6YN Wjyo7VnZ2dnUVZ_ tqtnZ2d@comcast .com...
              I'm not sure where the "tblClients Row" came from, but theDataset.Tabl es 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.Tabl es("theTableNam e").
              >
              >
              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
              >tblClientsTabl eAdapter and tblClients?
              >Many thanks again.
              >>
              >Regards
              >>
              >"Bill McCarthy" <Bill@N0SPAM.co mwrote in message
              >news:F74696A 3-7F8F-4B46-B3D8-5505630C5E11@mi crosoft.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.Tabl es("tblClientsR ow"),
              >>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.in fovis.co.ukwrot e in message
              >>news:%23G1%23 8F0pIHA.2636@TK 2MSFTNGP04.phx. gbl...
              >>>Hi
              >>>>
              >>>I have below code which updates table tblClients and handles
              >>>concurrenc y 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.tblClientsTa bleAdapter.Upda te(Me.ContactsD ataSet.tblClien ts)
              >>>>
              >>> Catch dbcx As Data.DBConcurre ncyException
              >>> HanldeConcurren cy(dbcx.Row, ContactsDataSet .tblClientsRow)
              >>>>
              >>> End Try
              >>>>
              >>>End Sub
              >
              >

              Comment

              • Cor Ligthert[MVP]

                #8
                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.



                Cor


                "John" <info@nospam.in fovis.co.ukschr eef in bericht
                news:%23G1%238F 0pIHA.2636@TK2M SFTNGP04.phx.gb l...
                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.tblClientsTa bleAdapter.Upda te(Me.ContactsD ataSet.tblClien ts)
                >
                Catch dbcx As Data.DBConcurre ncyException
                HanldeConcurren cy(dbcx.Row, ContactsDataSet .tblClientsRow)
                >
                End Try
                >
                End Sub
                >

                Comment

                Working...