Error: Specified cast is not valid

  • Thread starter Web Team @ Borough of Poole
  • Start date
W

Web Team @ Borough of Poole

Hi All,


When I run the below code, I get error 'Specified cast is not valid' on
line

163 Dim Address As OldInfra.BS7666.Address =
BS7666AddressCollection.GetSingleAddress(str_UPRN)

164 Dim easting As Integer = Address.Easting
165 Dim northing As Integer = Address.Northing

Address.Northing is an Integer in my class:

Me.Northing = CType(DR("Northing"), Integer)

Any advice anyone?


Thanks,
Simon.
 
T

TDAVISJR

User the debugger to see what kind of object is Me. Northing is OR do a
Response.Write("Me.Northing is of type: " & Me.Northing.GetType())

If you do not get Integer as your output then yeah, that cast will be
incorrect

Also, turn Option Strict on
 
K

Kevin Spencer

If Northing is Nothing, that would do it.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
What You Seek Is What You Get.
 
C

Craig Deelsnyder

Hi All,


When I run the below code, I get error 'Specified cast is not valid' on
line

163 Dim Address As OldInfra.BS7666.Address =
BS7666AddressCollection.GetSingleAddress(str_UPRN)

164 Dim easting As Integer = Address.Easting
165 Dim northing As Integer = Address.Northing

Address.Northing is an Integer in my class:

Me.Northing = CType(DR("Northing"), Integer)

Any advice anyone?


Thanks,
Simon.

Make sure DR("Nothing") isn't DBNull? Not sure what DR is, though...

http://www.freevbcode.com/ShowCode.asp?ID=5810
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,049
Latest member
Allen00Reed

Latest Threads

Top