Click here to Skip to main content
15,893,266 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:

VB
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 />


Please advise.

Thanks and best regards,
Furqan
Posted
Updated 13-Apr-11 21:31pm
v3
Comments
Dalek Dave 14-Apr-11 3:31am    
Edited for Grammar and Readability.

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


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

Good luck!
 
Share this answer
 
v4
Comments
Dalek Dave 14-Apr-11 3:31am    
Good Call.
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
 
Share this answer
 
v2
Comments
Dalek Dave 14-Apr-11 3:31am    
Good Answer.
The problem was with the bound of array. Solved ! Thanks everybody.
 
Share this answer
 
Comments
Ali Al Omairi(Abu AlHassan) 14-Apr-11 4:31am    
then accept any solution.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900