Confused!!
I am trying to fill a DataTable with a DataSet using a SQL query with one parameter. The parameter is the Node text of a treeview whose checkbox has been checked. It will retrieve Products from one table and any associated Packages from a different table. I am using a FOR loop to get which Products are 'checked' in the treeview and re-assigning the parameter for each loop. When the DataTable is populated it is giving me the correct data for the first item but just the last line of data for all others.
ie: If there are 4 Products with 6 Packages each the DataTable will list all 6 packages for the first Product and then only Package 6 for all others. I thought it was an issue with constraints in my database but have determined that is not the case. My query works fine for any individual Product that is checked in the treeview and my parameter is being picked up correctly throughout the For loop. Any ideas why I am only getting the last Package for any checked Products beyond the first? Any ideas would be most appreciated.
Thanks
My Query and VB code follows:
--------------------------------------------------------------------------
SELECT Products.ProductNumber, Products.Name,
Products.Mnemonic, AddOnPackages.PackageNumber,
AddOnPackages.Name AS Expr1,
AddOnPackages.Mnemonic AS Expr2
FROM Products LEFT OUTER JOIN
AddOnPackages ON
Products.ProductNumber = AddOnPackages.ProductNumber
WHERE (Products.Name = @ProdName)
ORDER BY Products.ProductNumber, AddOnPackages.PackageNumber
--------------------------------------------------------------------------
Dim ProdName As String = ""
For Each node As TreeNode In TreeView1.Nodes
If node.Checked = True Then
ProdName = node.Text
ReportForm.ProductsTableAdapter.ClearBeforeFill = False
ReportForm.ProductsTableAdapter.Fill
(ReportForm.ProductInfo.Products, ProdName)
End If
Next
I am trying to fill a DataTable with a DataSet using a SQL query with one parameter. The parameter is the Node text of a treeview whose checkbox has been checked. It will retrieve Products from one table and any associated Packages from a different table. I am using a FOR loop to get which Products are 'checked' in the treeview and re-assigning the parameter for each loop. When the DataTable is populated it is giving me the correct data for the first item but just the last line of data for all others.
ie: If there are 4 Products with 6 Packages each the DataTable will list all 6 packages for the first Product and then only Package 6 for all others. I thought it was an issue with constraints in my database but have determined that is not the case. My query works fine for any individual Product that is checked in the treeview and my parameter is being picked up correctly throughout the For loop. Any ideas why I am only getting the last Package for any checked Products beyond the first? Any ideas would be most appreciated.
Thanks
My Query and VB code follows:
--------------------------------------------------------------------------
SELECT Products.ProductNumber, Products.Name,
Products.Mnemonic, AddOnPackages.PackageNumber,
AddOnPackages.Name AS Expr1,
AddOnPackages.Mnemonic AS Expr2
FROM Products LEFT OUTER JOIN
AddOnPackages ON
Products.ProductNumber = AddOnPackages.ProductNumber
WHERE (Products.Name = @ProdName)
ORDER BY Products.ProductNumber, AddOnPackages.PackageNumber
--------------------------------------------------------------------------
Dim ProdName As String = ""
For Each node As TreeNode In TreeView1.Nodes
If node.Checked = True Then
ProdName = node.Text
ReportForm.ProductsTableAdapter.ClearBeforeFill = False
ReportForm.ProductsTableAdapter.Fill
(ReportForm.ProductInfo.Products, ProdName)
End If
Next