Ad Get All Rows From Database

- 1 answer

I am working on a a project (in which contains a database that holds information about products, a product object class, a product list object class, and a DB class which uses my stored procedure to pull all rows from the database (each row is constructed into a product, the products are put into an array list in the product list class). It seems to be working so far, except I am getting an error in my DB class that is stumping me.

 Dim TempList = New ArrayList
        Dim sqlDR As SqlClient.SqlDataReader = PDM.Data.SqlHelper.ExecuteReader(GLOBALS.ConnectionString, "sp_GetAllProducts")

        If sqlDR.HasRows Then
            While sqlDR.Read()
                Dim Prod As New Product
                Prod.PK_ProductID = sqlDR(0)
                Prod.MicrobeadStatus = sqlDR(1)
                Prod.FK_BrandID = sqlDR(2)
                Prod.FK_TypeID = sqlDR(3)
                Prod.FK_Product = sqlDR(4)
                Prod.PK_BrandID = sqlDR(5)
                Prod.BrandName = sqlDR(6)
                Prod.PK_Products = sqlDR(7)
                Prod.ProductName = sqlDR(8)
                Prod.PK_TypeID = sqlDR(9)
                Prod.Type = sqlDR(10)
            End While
        End If

In line 5 of this sample code, the word Product (a.k.a. my Product class) is saying that I haven't specified arguments for any of the parameters. PK_ProductID, MicrobeadStatus, etc. are all declared and put together with a constructor in the Product class. Nothing I have been trying so far seems to help. Any ideas?



As @Plutonix suggests in the comments, it sounds like Product doesn't have a parameterless constructor. If your Product constructors only have parameters then you must provide an argument to each one, e.g.

Dim Prod As New Product(sqlDR(0), ...)

If you want to be able to create an instance without providing any arguments then you must declare a parameterless constructor, e.g.

Public Sub New()
End Sub