在数据库中将值存储在数组中时出现问题 [英] Problem storing value in array from database

查看:79
本文介绍了在数据库中将值存储在数组中时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想从数据库中将值存储在数组中.
我正在使用以下代码,但返回错误:对象引用未设置为对象的实例."

代码是:

Hi,

I want to store values in an 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")"<br />



请指教.

谢谢和最诚挚的问候,
Furqan



Please advise.

Thanks and best regards,
Furqan

推荐答案

将您的条件修改为

Hi, modify your condition to

Dim limit as integer = DsChooseSQsNow.tblChooseSQs.Rows.Count

Do While limit > 0 AND w <= limit
    vrSQsNoChosen(w) = DsChooseSQsNow.tblChooseSQs.Rows(w).Item("QNo")
    vrTotalSQsChosen = vrTotalSQsChosen + 1
    w = w + 1
Loop



另外,请检查DsChooseSQsNow.tblChooseSQs.Rows是否具有值.

祝你好运!



Also, check the DsChooseSQsNow.tblChooseSQs.Rows if it has a value.

Good luck!


贬值

decalration

dim ds as new dataset
dim da as new olebd.oldataadapter
dim sqlstring as string

sqlstring="sellect Qno from tablename"
da=new oledb.oledbdataadapter(sql,con)
con.open
da.fill(ds,"tablename")
dim temp as integer=ds.tables("tablename").rows.count;
dim arr() as integer
for i=0 to temp-1
arr(i)=ds.tables("tablename").rows(i).item("Qno")


next





shatrughna





shatrughna


问题出在数组的边界上.解决了 !谢谢大家.
The problem was with the bound of array. Solved ! Thanks everybody.


这篇关于在数据库中将值存储在数组中时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆