4 Replies - 2691 Views - Last Post: 11 October 2012 - 03:38 PM Rate Topic: -----

#1 S-John  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 51
  • Joined: 13-July 12

[VB.NET 2010] List Population from a DataSet/DataTable

Posted 04 October 2012 - 01:55 PM

I had this program working a while ago and I came back to it and am having some issues. I am able to Populate a List from a DataSet well enough but for some reason my initial List persists through all other lists that I try to populate after that. That is to say that the DataSet for the first Parts group is copied over into all other datasets throughout the application.
Private Sub RetrieveProtectionFromDB()
        Try
            Using udtconn As New SqlConnection(sBoMConnectionString)

                udtconn.Open()
                Dim daProtection As New SqlDataAdapter(New SqlCommand("SELECT * FROM Part, Part_Type, Part_Subtype, Part_Type_Subtype_Xref, Part_Details_Motor WHERE Part.Part_Type_Xref_Id = Part_Type_Subtype_Xref.Part_Type_Xref_Id AND Part_Type_Subtype_Xref.Part_Type_Id = Part_Type.Part_Type_Id AND Part_Type_Subtype_Xref.Part_Subtype_Id = Part_Subtype.Part_Subtype_Id AND Part.Master_Part_Id = Part_Details_Motor.Master_Part_Id And Part_Type.Part_Type_Name = 'Motor Protection'", udtconn))
                udtconn.Close()

                daProtection.Fill(ds)
                daProtection.Fill(dt)

                'Creates new motor class with the information that was pulled from the database
                Dim newProtection As New clsMotorProtection()
                newProtection.ProtectionHorsepower = CType(dt.Rows(0).Item("Horsepower"), Decimal)
                newProtection.ProtectionPartType = CType(dt.Rows(0).Item("Part_Type_Name"), String)
                newProtection.ProtectionPartSubType = CType(dt.Rows(0).Item("Part_Subtype_Name"), String)
                newProtection.ProtectionPartNumber = CType(dt.Rows(0).Item("Part_Nbr"), String)
                newProtection.ProtectionManufacturer = CType(dt.Rows(0).Item("Manufacturer_Name"), String)
                newProtection.ProtectionVendor = CType(dt.Rows(0).Item("Vendor_Name"), String)
                newProtection.ProtectionDescription = CType(dt.Rows(0).Item("Part_Desc"), String)
                newProtection.ProtectionPrice = CType(dt.Rows(0).Item("Last_Quote_Amt"), Double)
                newProtection.ProtectionQuantity = spnMotorQTY.Value
                newProtection.AddedGroupID = iAddedMotorGroupID

                lstProtection.Add(newProtection)
            End Using
        Catch ex As Exception
            'An error occured while pulling data
        End Try
    End Sub
'------------------------------------------------------------------------------------------
Private Sub RetrieveMotorControllerFromDB()
        Try
            Using udtconn As New SqlConnection(sBoMConnectionString)

                udtconn.Open()
                Dim daMotorControllers As New SqlDataAdapter(New SqlCommand("SELECT * FROM Part, Part_Type, Part_Subtype, Part_Type_Subtype_Xref, Part_Details_Motor WHERE Part.Part_Type_Xref_Id = Part_Type_Subtype_Xref.Part_Type_Xref_Id AND Part_Type_Subtype_Xref.Part_Type_Id = Part_Type.Part_Type_Id AND Part_Type_Subtype_Xref.Part_Subtype_Id = Part_Subtype.Part_Subtype_Id AND Part.Master_Part_Id = Part_Details_Motor.Master_Part_Id And Part_Type.Part_Type_Name = 'Motor Controller'", udtconn))
                udtconn.Close()

                daMotorControllers.Fill(ds)
                daMotorControllers.Fill(dt)

                'Creates new motor controller class with the information that was pulled from the database
                Dim newMotorController As New clsMotorController()
                newMotorController.MotorControllerHorsepower = CType(dt.Rows(0).Item("Horsepower"), Decimal)
                newMotorController.MotorControllerPartType() = CType(dt.Rows(0).Item("Part_Type_Name"), String)
                newMotorController.MotorControllerPartSubType = CType(dt.Rows(0).Item("Part_Subtype_Name"), String)
                newMotorController.MotorControllerManufacturer() = CType(dt.Rows(0).Item("Manufacturer_Name"), String)
                newMotorController.MotorControllerPartNumber = CType(dt.Rows(0).Item("Part_Nbr"), String)
                newMotorController.MotorControllerVendor = CType(dt.Rows(0).Item("Vendor_Name"), String)
                newMotorController.MotorControllerDescription = CType(dt.Rows(0).Item("Part_Desc"), String)
                newMotorController.MotorControllerPrice = CType(dt.Rows(0).Item("Last_Quote_Amt"), Double)
                newMotorController.MotorControllerQuantity = spnMotorQTY.Value
                newMotorController.AddedGroupID = iAddedMotorGroupID

                lstMotorController.Add(newMotorController)
            End Using
        Catch ex As Exception
            'An error occured while pulling data
        End Try
    End Sub


I put two DataSets on here so you can compare.
Also, i apologize for the length of the code. I know it could be more concise but this is a pickup project.

Thanks for any insight you may offer,

--Seth

Is This A Good Question/Topic? 0
  • +

Replies To: [VB.NET 2010] List Population from a DataSet/DataTable

#2 lucky3  Icon User is offline

  • Friend lucky3 As IHelpable
  • member icon

Reputation: 231
  • View blog
  • Posts: 765
  • Joined: 19-October 11

Re: [VB.NET 2010] List Population from a DataSet/DataTable

Posted 05 October 2012 - 02:53 AM

If you have only one ds as DataSet, then it will have all tables in it. I don't see new DataSet instantiation in your code, so that might be it.
Was This Post Helpful? 1
  • +
  • -

#3 rgfirefly24  Icon User is offline

  • D.I.C Lover
  • member icon


Reputation: 278
  • View blog
  • Posts: 1,486
  • Joined: 07-April 08

Re: [VB.NET 2010] List Population from a DataSet/DataTable

Posted 05 October 2012 - 05:43 AM

I would highly recommend giving each of your tables within your DataSet a name. This will give you the ability to quickly access each of your tables within the DataSet using this name. You can do that by adding a table to your SqlDataAdapter using this:

daProtection .TableMappings.Add("Table", "Products")



Then you can retrieve it out by using this:

ds.Tables("Products")


This post has been edited by rgfirefly24: 05 October 2012 - 05:44 AM

Was This Post Helpful? 1
  • +
  • -

#4 S-John  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 51
  • Joined: 13-July 12

Re: [VB.NET 2010] List Population from a DataSet/DataTable

Posted 05 October 2012 - 07:34 AM

Thanks guys. I'll name my DataSet tables on Monday. :)
Was This Post Helpful? 0
  • +
  • -

#5 S-John  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 51
  • Joined: 13-July 12

Re: [VB.NET 2010] List Population from a DataSet/DataTable

Posted 11 October 2012 - 03:38 PM

Ok. I am now having an issue with displaying any of the information. And I cannot find a breakpoint that will allow me to view if the datatables and dataset are filling because it runs right through them...

Private Sub RetrieveProtectionFromDB()
        Try
            Using udtconn As New SqlConnection(sBoMConnectionString)

                udtconn.Open()
                Dim daProtection As New SqlDataAdapter(New SqlCommand("SELECT * FROM Part, Part_Type, Part_Subtype, Part_Type_Subtype_Xref, Part_Details_Motor WHERE Part.Part_Type_Xref_Id = Part_Type_Subtype_Xref.Part_Type_Xref_Id AND Part_Type_Subtype_Xref.Part_Type_Id = Part_Type.Part_Type_Id AND Part_Type_Subtype_Xref.Part_Subtype_Id = Part_Subtype.Part_Subtype_Id AND Part.Master_Part_Id = Part_Details_Motor.Master_Part_Id And Part_Type.Part_Type_Name = 'Motor Protection'", udtconn))

                Dim dtProtection As New DataTable("Motor_Protection")
                daProtection.Fill(dsPart, "Motor_Protection")
                dsPart.Tables.Add(dtProtection)
                udtconn.Close()
                'Creates new motor class with the information that was pulled from the database
                Dim newProtection As New clsMotorProtection()
                newProtection.ProtectionHorsepower = CType(dsPart.Tables("Motor_Protection").Rows(0).Item("Horsepower"), Decimal)
                newProtection.ProtectionPartType = CType(dsPart.Tables("Motor_Protection").Rows(0).Item("Part_Type_Name"), String)
                newProtection.ProtectionPartSubType = CType(dsPart.Tables("Motor_Protection").Rows(0).Item("Part_Subtype_Name"), String)
                newProtection.ProtectionPartNumber = CType(dsPart.Tables("Motor_Protection").Rows(0).Item("Part_Nbr"), String)
                newProtection.ProtectionManufacturer = CType(dsPart.Tables("Motor_Protection").Rows(0).Item("Manufacturer_Name"), String)
                newProtection.ProtectionVendor = CType(dsPart.Tables("Motor_Protection").Rows(0).Item("Vendor_Name"), String)
                newProtection.ProtectionDescription = CType(dsPart.Tables("Motor_Protection").Rows(0).Item("Part_Desc"), String)
                newProtection.ProtectionPrice = CType(dsPart.Tables("Motor_Protection").Rows(0).Item("Last_Quote_Amt"), Double)
                newProtection.ProtectionQuantity = spnMotorQTY.Value
                newProtection.AddedGroupID = iAddedMotorGroupID

                lstProtection.Add(newProtection)
            End Using
        Catch ex As Exception
            'An error occured while pulling data
        End Try

    End Sub


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1