Refer to TableAdapter data in code?

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

    #1

    Refer to TableAdapter data in code?

    I'm wanting to find the value of TableID on the current record displayed on
    my form. I cannot seem to find any method within the TableAdapter class to
    find this. An example I've found MS uses a bound control on the form and
    then refers to the forms .text property. TableID is not displayed on the
    form nor do I want it to be, so it does not have a bound control.

    I've also ready that every TableAdapter has an associated DataTable class
    which is actually what is populated with the data. Unfortunately I have not
    been able to find a property in either class to find the value of a single
    field in the current record.

    Thanks,
    Ryan


  • Linda Liu [MSFT]

    #2
    RE: Refer to TableAdapter data in code?

    Hi Ryan,

    Thank you for posting.

    Is the DataID a field in your DataTable?

    You can get the value of any field in a datarow in a DataTable by using the
    Rows collection of the DataTable. Suppose there's a DataTable named
    "ClassesTab le1" with two fields "ClassID" and "ClassName" in it. Then we
    can get the values of the two fields in the second datarow by the following
    statements:

    dim var1 as Integer = ClassesTable1.R ows(1)("ClassID ")
    dim var2 as String = ClassesTable1.R ows(1)("ClassNa me")

    If you have anything unclear, don't hesitate to get in touch. I look
    forward to your reply.


    Sincerely,
    Linda Liu
    Microsoft Online Community Support

    =============== =============== =============== =======
    When responding to posts,please "Reply to Group" via
    your newsreader so that others may learn and benefit
    from your issue.
    =============== =============== =============== =======

    Comment

    • Ryan

      #3
      Re: Refer to TableAdapter data in code?

      Hi Linda,

      Yes DataID is a field in the DataTable. I'm trying to refer to the
      DataTable associated with a DataSet that is used to bind controls on my
      form. So I would assume the syntax would be as such:

      Me.myDataSet.my DataTable.Rows( <<what do I put here>>)("DataID ")

      What do I put to get the current record displayed on the form (the row)?

      Thanks,
      Ryan

      "Linda Liu [MSFT]" <v-lliu@online.mic rosoft.com> wrote in message
      news:3qCeH9SkGH A.4948@TK2MSFTN GXA01.phx.gbl.. .[color=blue]
      > Hi Ryan,
      >
      > Thank you for posting.
      >
      > Is the DataID a field in your DataTable?
      >
      > You can get the value of any field in a datarow in a DataTable by using
      > the
      > Rows collection of the DataTable. Suppose there's a DataTable named
      > "ClassesTab le1" with two fields "ClassID" and "ClassName" in it. Then we
      > can get the values of the two fields in the second datarow by the
      > following
      > statements:
      >
      > dim var1 as Integer = ClassesTable1.R ows(1)("ClassID ")
      > dim var2 as String = ClassesTable1.R ows(1)("ClassNa me")
      >
      > If you have anything unclear, don't hesitate to get in touch. I look
      > forward to your reply.
      >
      >
      > Sincerely,
      > Linda Liu
      > Microsoft Online Community Support
      >
      > =============== =============== =============== =======
      > When responding to posts,please "Reply to Group" via
      > your newsreader so that others may learn and benefit
      > from your issue.
      > =============== =============== =============== =======
      >[/color]


      Comment

      • Ryan

        #4
        Re: Refer to TableAdapter data in code?

        Well only took nearly a day to stumble across this, but here's how you do
        it:
        To refer to a field in the row of data currently on your form (for example
        if you want to see DataID, but DataID is not bound to any form control):

        Me.myDataSet.my Table.Rows(Me.m yBindingSource. Position)("Data ID")

        Whew!

        "Ryan" <Tyveil@newsgro ups.nospam> wrote in message
        news:uK79CPUkGH A.1508@TK2MSFTN GP04.phx.gbl...[color=blue]
        > Hi Linda,
        >
        > Yes DataID is a field in the DataTable. I'm trying to refer to the
        > DataTable associated with a DataSet that is used to bind controls on my
        > form. So I would assume the syntax would be as such:
        >
        > Me.myDataSet.my DataTable.Rows( <<what do I put here>>)("DataID ")
        >
        > What do I put to get the current record displayed on the form (the row)?
        >
        > Thanks,
        > Ryan
        >
        > "Linda Liu [MSFT]" <v-lliu@online.mic rosoft.com> wrote in message
        > news:3qCeH9SkGH A.4948@TK2MSFTN GXA01.phx.gbl.. .[color=green]
        >> Hi Ryan,
        >>
        >> Thank you for posting.
        >>
        >> Is the DataID a field in your DataTable?
        >>
        >> You can get the value of any field in a datarow in a DataTable by using
        >> the
        >> Rows collection of the DataTable. Suppose there's a DataTable named
        >> "ClassesTab le1" with two fields "ClassID" and "ClassName" in it. Then we
        >> can get the values of the two fields in the second datarow by the
        >> following
        >> statements:
        >>
        >> dim var1 as Integer = ClassesTable1.R ows(1)("ClassID ")
        >> dim var2 as String = ClassesTable1.R ows(1)("ClassNa me")
        >>
        >> If you have anything unclear, don't hesitate to get in touch. I look
        >> forward to your reply.
        >>
        >>
        >> Sincerely,
        >> Linda Liu
        >> Microsoft Online Community Support
        >>
        >> =============== =============== =============== =======
        >> When responding to posts,please "Reply to Group" via
        >> your newsreader so that others may learn and benefit
        >> from your issue.
        >> =============== =============== =============== =======
        >>[/color]
        >
        >[/color]


        Comment

        • Ryan

          #5
          Re: Refer to TableAdapter data in code?

          Oh and the title of these posts are probably misleading. The TableAdapter
          doesn't actually hold any data, it's just a nice tool for transferring data
          back and forth from an actual database to a DataSet object. It's taken me
          awile to figure out just how .NET 2.0 works.

          "Ryan" <Tyveil@newsgro ups.nospam> wrote in message
          news:emkB4BYkGH A.3536@TK2MSFTN GP05.phx.gbl...[color=blue]
          > Well only took nearly a day to stumble across this, but here's how you do
          > it:
          > To refer to a field in the row of data currently on your form (for example
          > if you want to see DataID, but DataID is not bound to any form control):
          >
          > Me.myDataSet.my Table.Rows(Me.m yBindingSource. Position)("Data ID")
          >
          > Whew!
          >
          > "Ryan" <Tyveil@newsgro ups.nospam> wrote in message
          > news:uK79CPUkGH A.1508@TK2MSFTN GP04.phx.gbl...[color=green]
          >> Hi Linda,
          >>
          >> Yes DataID is a field in the DataTable. I'm trying to refer to the
          >> DataTable associated with a DataSet that is used to bind controls on my
          >> form. So I would assume the syntax would be as such:
          >>
          >> Me.myDataSet.my DataTable.Rows( <<what do I put here>>)("DataID ")
          >>
          >> What do I put to get the current record displayed on the form (the row)?
          >>
          >> Thanks,
          >> Ryan
          >>
          >> "Linda Liu [MSFT]" <v-lliu@online.mic rosoft.com> wrote in message
          >> news:3qCeH9SkGH A.4948@TK2MSFTN GXA01.phx.gbl.. .[color=darkred]
          >>> Hi Ryan,
          >>>
          >>> Thank you for posting.
          >>>
          >>> Is the DataID a field in your DataTable?
          >>>
          >>> You can get the value of any field in a datarow in a DataTable by using
          >>> the
          >>> Rows collection of the DataTable. Suppose there's a DataTable named
          >>> "ClassesTab le1" with two fields "ClassID" and "ClassName" in it. Then we
          >>> can get the values of the two fields in the second datarow by the
          >>> following
          >>> statements:
          >>>
          >>> dim var1 as Integer = ClassesTable1.R ows(1)("ClassID ")
          >>> dim var2 as String = ClassesTable1.R ows(1)("ClassNa me")
          >>>
          >>> If you have anything unclear, don't hesitate to get in touch. I look
          >>> forward to your reply.
          >>>
          >>>
          >>> Sincerely,
          >>> Linda Liu
          >>> Microsoft Online Community Support
          >>>
          >>> =============== =============== =============== =======
          >>> When responding to posts,please "Reply to Group" via
          >>> your newsreader so that others may learn and benefit
          >>> from your issue.
          >>> =============== =============== =============== =======
          >>>[/color]
          >>
          >>[/color]
          >
          >[/color]


          Comment

          • Linda Liu [MSFT]

            #6
            Re: Refer to TableAdapter data in code?

            Hi Ryan,

            Thanks for your response.

            Yes, you could use the Position property of the myBindingSource to get the
            position of the current datarow. You could also use the Current property of
            the myBindingSource to get the current datarow directly.

            For example, the statement
            "((DataRowView) Me.myBindingSou rce.Current)("D ataID") " is equal to the
            statement
            "Me.myDataSet.m yTable.Rows(Me. myBindingSource .Position)("Dat aID")".

            If you have any other questions, please do not hesitate to contact us. It
            is always our pleasure to be of assistance.

            Have a nice day!


            Sincerely,
            Linda Liu
            Microsoft Online Community Support

            =============== =============== =============== =======
            When responding to posts,please "Reply to Group" via
            your newsreader so that others may learn and benefit
            from your issue.
            =============== =============== =============== =======

            Comment

            • Ryan

              #7
              Re: Refer to TableAdapter data in code?

              Thanks Linda,

              I was wondering about the .current property. Actually I was having some
              buggy behavior with my code and once I replaced it with yours it now works
              properly.

              Ryan

              "Linda Liu [MSFT]" <v-lliu@online.mic rosoft.com> wrote in message
              news:PxDOGx3kGH A.5184@TK2MSFTN GXA01.phx.gbl.. .[color=blue]
              > Hi Ryan,
              >
              > Thanks for your response.
              >
              > Yes, you could use the Position property of the myBindingSource to get the
              > position of the current datarow. You could also use the Current property
              > of
              > the myBindingSource to get the current datarow directly.
              >
              > For example, the statement
              > "((DataRowView) Me.myBindingSou rce.Current)("D ataID") " is equal to the
              > statement
              > "Me.myDataSet.m yTable.Rows(Me. myBindingSource .Position)("Dat aID")".
              >
              > If you have any other questions, please do not hesitate to contact us. It
              > is always our pleasure to be of assistance.
              >
              > Have a nice day!
              >
              >
              > Sincerely,
              > Linda Liu
              > Microsoft Online Community Support
              >
              > =============== =============== =============== =======
              > When responding to posts,please "Reply to Group" via
              > your newsreader so that others may learn and benefit
              > from your issue.
              > =============== =============== =============== =======
              >[/color]


              Comment

              • Linda Liu [MSFT]

                #8
                Re: Refer to TableAdapter data in code?

                Hi Ryan,

                Thank you for your response.

                The Current property of the myBindingSource gets the current item in the
                list. The type of the value of this property is object. To use this value,
                you should cast it to a properly type. In this case, the type of the items
                in the myBindingSource is DataRowView. So you should cast the value to the
                type of DataRowView.

                If you have any other questions, please don't hesitate to let me know.


                Sincerely,
                Linda Liu
                Microsoft Online Community Support

                =============== =============== =============== =======
                When responding to posts,please "Reply to Group" via
                your newsreader so that others may learn and benefit
                from your issue.
                =============== =============== =============== =======

                Comment

                Working...