0

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")"

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

I printed DsChooseSQsNow.tblChooseSQs.Rows(w).Item("QNo") and value is not Null
0

There are many reasons why this code fails. I would start checking from:

  • Size (and boundings) of 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

1 Comment

The problem was with the bound of array. Solved ! Thanks a lot.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.