DataSet Tables throwing a "non-shared member" error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • maxcad
    New Member
    • Jan 2014
    • 5

    DataSet Tables throwing a "non-shared member" error

    Using vb.net 1020
    my code is fairly simple. I have a dataset with the named table in it, but I get an error on VM_Sandbox2Data Set.Tables as "Reference to a non-shared member requires an object reference."

    Code:
    Dim table As DataTable = VM_Sandbox2DataSet.Tables("OTQ_CUST_UNIT")
            Dim rows() As DataRow = table.Select("Supply_Base_ID = '" & OtqSerNo_TextBox.Text & "' AND SUPPLY_LOT_ID = '" & LotID & "'")
    What am I missing?
  • Luk3r
    Contributor
    • Jan 2014
    • 300

    #2
    I think you have to create an instance of your dataset

    Code:
    Dim dSet As New DataSet
    Hope this helps!

    Comment

    • maxcad
      New Member
      • Jan 2014
      • 5

      #3
      BAsed on that, I assume this is what you meant
      Code:
      Dim dSet As New VM_Sandbox2DataSet
      Dim table As DataTable = dSet.Tables("OTQ_CUST_UNIT")
      I must be doing something wrong. While I have no errors, I also have no data showing in the table even though there are 30 records.

      Comment

      • Luk3r
        Contributor
        • Jan 2014
        • 300

        #4
        Yes. That's what I meant. Are you by chance using a Try..Catch? If so, either tell the exception to throw you a messagebox with the details, or eliminate the Try..Catch so you can see where your code is failing.

        Comment

        • maxcad
          New Member
          • Jan 2014
          • 5

          #5
          I don't think it's a coding issue. I do a SELECT form the table and get zero rows.
          Code:
          Dim dSet As New VM_Sandbox2DataSet
          Dim table As DataTable = dSet.Tables("OTQ_CUST_UNIT")
          Dim rows() As DataRow = table.Select()
          MsgBox(rows.Count.ToString)
          What am I missing?

          Comment

          • Luk3r
            Contributor
            • Jan 2014
            • 300

            #6
            Without recreating your table I'm kind of shooting from the hip here, but, maybe the row count section is wrong. Try something like this:

            Code:
            MsgBox(dset.Tables(0).Rows.Count.ToString)
            Edit*: Where 0 is identifying the first table in your dataset.

            Comment

            • maxcad
              New Member
              • Jan 2014
              • 5

              #7
              Strangely all six of the tables show the correct table names, but zero records when running. There is plenty of data when I preview the data from the DataSource bar.

              Comment

              • Luk3r
                Contributor
                • Jan 2014
                • 300

                #8
                And you tried my code suggestion and it did not work?

                Comment

                • Luk3r
                  Contributor
                  • Jan 2014
                  • 300

                  #9
                  I got it on my side. First, you need to make sure on your Form.vb, in design mode, that you add your Dataset and Database Table Adapter (add them sort of like a button or anything else. They are located under your Database Components).

                  Then it's as simple as doing this:
                  Code:
                  Me.DatabaseTableAdapter1.Fill(Me.DataSet1.NameOfTable
                  MsgBox(Dataset1.Tables(0).Rows.Count)

                  Comment

                  Working...