-
October 4th, 2012, 03:37 PM
#1
[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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|