473,785 Members | 2,851 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Error: Specified cast is not valid

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 =
BS7666AddressCo llection.GetSin gleAddress(str_ UPRN)

164 Dim easting As Integer = Address.Easting
165 Dim northing As Integer = Address.Northin g

Address.Northin g is an Integer in my class:

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

Any advice anyone?
Thanks,
Simon.

Nov 19 '05 #1
4 1353
User the debugger to see what kind of object is Me. Northing is OR do a
Response.Write( "Me.Northin g is of type: " & Me.Northing.Get Type())

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

Also, turn Option Strict on

--
TDAVISJR
aka - Tampa.NET Koder
"Web Team @ Borough of Poole" <we*********@po ole.gov.uk> wrote in message
news:11******** **************@ o13g2000cwo.goo glegroups.com.. .
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 =
BS7666AddressCo llection.GetSin gleAddress(str_ UPRN)

164 Dim easting As Integer = Address.Easting
165 Dim northing As Integer = Address.Northin g

Address.Northin g is an Integer in my class:

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

Any advice anyone?
Thanks,
Simon.

Nov 19 '05 #2
If Northing is Nothing, that would do it.

--
HTH,

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

"Web Team @ Borough of Poole" <we*********@po ole.gov.uk> wrote in message
news:11******** **************@ o13g2000cwo.goo glegroups.com.. .
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 =
BS7666AddressCo llection.GetSin gleAddress(str_ UPRN)

164 Dim easting As Integer = Address.Easting
165 Dim northing As Integer = Address.Northin g

Address.Northin g is an Integer in my class:

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

Any advice anyone?
Thanks,
Simon.

Nov 19 '05 #3
On Mon, 25 Apr 2005 09:01:22 -0500, Web Team @ Borough of Poole
<we*********@po ole.gov.uk> wrote:
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 =
BS7666AddressCo llection.GetSin gleAddress(str_ UPRN)

164 Dim easting As Integer = Address.Easting
165 Dim northing As Integer = Address.Northin g

Address.Northin g is an Integer in my class:

Me.Northing = CType(DR("North ing"), 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
--
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET
Nov 19 '05 #4
Thanks everyone - Northing was indeed Nothing! :)

Nov 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
5840
by: Ron Holmes | last post by:
I posted this question on the Crystal Reports Support site and I am still waiting for an answer. Using Crystal Reports 9.0 Developer Full edition: My Crystal report .RPT file has a Picture box which is an OLE Object located in the Page Header section of my .RPT file. This is the call which works perfectly in VB6 to format the crystal reports Page Header section of my report file EquipLst.rpt.
13
3327
by: LL | last post by:
Hi, How to fix this problem: Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.InvalidCastException: Specified cast is not valid.
5
3975
by: .Net Sports | last post by:
I have a datagrid codebehind script that takes data from sql dbase and displays it in a footer row as a total. One column has amount_dollars (which works fine), while another has new sales (which is "newstotal"), but I'm getting an error (System.InvalidCastException: Specified cast is not valid) from the newstotal line: price = (Decimal)(rowData); newstotal = (rowData); newstotal is an integer, just wondering what datatype i should use
4
5758
by: SRLoka | last post by:
I have an application that has five threads. All five threads write to the same MSMQ. All five threads are using the same global instance to send data to the MSMQ server(on same machine). Occasionally, I get the erroror below. The data(string) being sent is not null or empty. Is this a problem related to multiple threads ? Right now I have coded it like this Controller.MSMQ.Send(Record); Should I change to
8
9469
by: Razak | last post by:
Hi, I have a class which basically do Impersonation in my web application. From MS KB sample:- ++++++++++++++++++++code starts Dim impersonationContext As System.Security.Principal.WindowsImpersonationContext Dim currentWindowsIdentity As System.Security.Principal.WindowsIdentity
5
1900
by: Alan Silver | last post by:
Hello, I have an ASP.NET page where I am grabbing an SqlDataReader and using it to populate some controls on the form. Amongst the fields pulled out of the table are two integer fields, which I am trying to cast as strings so they can be displayed in a Literal control. I am using the following code (heavily edited for clarity) ... if (dtrDilemmas.Read()) {
1
1403
by: .Net Sports | last post by:
I have a datagrid codebehind script that takes data from sql dbase and displays it in a footer row as a total. One column has amount_dollars (which works fine), while another has new sales (which is "newstotal"), but I'm getting an error (System.InvalidCastException: Specified cast is not valid) from the newstotal line: price = (Decimal)(rowData); newstotal = (rowData); newstotal is an integer, just wondering what datatype i should use
0
1975
by: kcm | last post by:
Hello all, Not sure if this is the right place to post this. I ran up the samples for adventureworks for MSSQL2005. I setup the shop front. The web site is up. But when I try to register a new user via the web page I get this error. Specified cast is not valid. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it...
3
3699
by: keithb | last post by:
Using a GridView, I get a "Specified cast is not valid" error when binding the Visible propery of a hyperlink control to a DataTable text field. The error goes away if I replace the data binding statement with "true" or "false". This code causes the error: <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# Eval("c2Hyperlink1Link") %>' Target="_blank"
1
4441
vinci
by: vinci | last post by:
Please help me out... i only have two weeks to do it... here is my code: Dim ex As New Object Dim wb As Excel.Workbook Dim sheet As Excel.Worksheet
0
9645
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10152
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10092
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9950
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8974
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6740
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3650
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2880
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.