CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 2012
    Posts
    46

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

    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.

    Code:
    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

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

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

    Can't really say without seeing the DATA. Probably would help you as well.

    DEBUG.PRINT out the statements (VB6, sorry). Probably not what you expect
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured