Reputation: 4997
I want to store value in array, from my database. I am using following code but it return error: "Object reference not set to an instance of an object."
Code is:
Dim w as integer=0
Do While DsChooseSQsNow.tblChooseSQs.Rows.Count > w
vrSQsNoChosen(w) = DsChooseSQsNow.tblChooseSQs.Rows(w).Item("QNo")
vrTotalSQsChosen = vrTotalSQsChosen + 1
w = w + 1
Loop
Error comes on "vrSQsNoChosen(w) = DsChooseSQsNow.tblChooseSQs.Rows(w).Item("QNo")"
Upvotes: 0
Views: 210
Reputation: 4129
try to print the value DsChooseSQsNow.tblChooseSQs.Rows(w).Item("QNo")
or debug the code
"Object reference not set to an instance of an object." means Item("QNo") may be null
Upvotes: 1
Reputation: 11232
There are many reasons why this code fails. I would start checking from:
vrSQsNoChosen
array.w
value when error occurs (is valid index for vrSQsNoChosen
array and Rows
collection?).Item("QNo")
value when error occurs (maybe is null
?).Also -- VB.NET implements +=
operator so you can write:
w += 1
instead of:
w = w + 1
Upvotes: 0