"Object reference not set to an object" again

nmilstein

New member
Joined
Jul 27, 2006
Messages
2
Programming Experience
Beginner
Hi!

That said, I have been trying to
write something in bits and pieces.
Most of it works (quite surprisingly!).
However, this snippet is causing me
quite some trouble:

VB.NET:
MsgBox(CType(DS.Tables("OIDdid" & _
OID("OID")), DataTable).Rows.Count)
Dim MID As DataRow, i As Integer
For i = 0 To CType(DS.Tables("OIDmid" & _
OID("OID")), DataTable).Rows.Count - 1
where DS is a dataset and OIDdidxxx has
been previously created (and data entered).
The MsgBox gives me the expected number.
However, the similar expression in the "for"
condition gives me an "Object reference not
set to an object" exception. I had originally
tried it as:

VB.NET:
For Each MID as Datarow in DS.Tables("OIDmid" & _
OID("OID")).Rows

but that gives me the same expression.

Anyone know what may have gone wrong?
Suggestions?

Thanks in advance!

PS: PLEASE don't ask me to post a more complete
code fragment. The code preceding it uses a custom
control, which calls a custom type, which I think calls
another custom type. I'd rather not spend a whole
afternoon fishing out the smallest set of code for it
to be readable. Of course, if the problem doesn't seem
to arise from the code posted above, I won't have much
choice :(
 
Last edited by a moderator:

vis781

Well-known member
Joined
Aug 30, 2005
Messages
2,015
Location
Cambridge, UK
Programming Experience
5-10
The easiest way to deal with this kind of exception is to set a breakpoint and then step through the code, hang your mouse pointer over every variable and one of them will say "... = nothing" theres where your exception is being thrown.
 

nmilstein

New member
Joined
Jul 27, 2006
Messages
2
Programming Experience
Beginner
Problem solved

Thank you for your input.

I finally discovered the mistake:
I wrote "OIDmid" instead of "OIDdid"...
Made me crazy!
 
Top Bottom