Vb.net Get All Rows From Database
I am working on a a project (in VB.net) 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) TempList.Add(Prod) 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
- → I can't do a foreign key, constraint error
- → How to implement DbDongle::convertTimestamps as workaround of invalid timestamps with MySql strict
- → MySQL error "Foreign key constraint is incorrectly formed"
- → Eloquent Multitable query
- → "Laravel 5.1" add user and project with userId
- → Database backup with custom code in laravel 5 and get the data upto 10 rows from per table in database
- → Laravel 5.1 QueryException when trying to delete a project
- → Using Array in '->where()' for Laravel Query Building
- → Chaining "Count of Columns" of a Method to Single Query Builder
- → Laravel Eloquent Joining Strange query
- → convert time using mysql laravel 5
- → How to update a column after an expiration date in MySQL?
- → Foreign key constraint fails on existing key