开发者

Problem storing value in array

开发者 https://www.devze.com 2023-02-25 18:14 出处:网络
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 objec开发者_运维百科t.\"

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 objec开发者_运维百科t."

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


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


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
0

精彩评论

暂无评论...
验证码 换一张
取 消