我不确定如何正确表达我的问题,但我想实现这样的目标。
我有一个名为 Products 的课程
public class Products
private ID as Integer
private Name as String
Public Property ProductID()
Get
Return ID
End Get
Set(ByVal value)
ID = value
End Set
End Property
在我的页后代码中,我从 SQL 命令中检索数据并将其放入数据读取器对象中。
我如何能够声明该类,以便我的 datareader 中的每一行实际上都是所述类的实例?
例如:
Dim myProduct() as New Product
Dim intCnt as Integer
While datareaderData.read()
intCnt += 1
myProduct(intCnt) = new Product
myProduct(intCnt).ID = datareaderData("ID")
myProduct(intCnt).Name = datareaderData("Name")
End While
当我这样做时,我收到一个错误“对象引用未设置为对象的实例。
我对这个很困惑。非常感谢任何提示。谢谢。