473,848 Members | 1,568 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

invalid cast exception

I am getting an invalid cast exception - cast from string to type
double is not valid.

Dim curName As String
Dim prevName As String = ""
curName = CStr(rows.Item( i).Item(colSchN ame)) ' extract name from
database row
If (curName.Compar eTo(prevName <> 0)) Then <--- exception occurs on
this line

I do a cast on line 3 but that is not the one getting an exception. Any
help appreciated...c harlie

Nov 21 '05 #1
6 2617
CS,

Any reason that you do not just

\\\
If curName <> "" then
///

You make me curious

Cor
Nov 21 '05 #2
THis is the first time through. If these are not equal then I save it
in a list , assing curname to prevname and go to the next. I'm trying
to eliminate any duplicates during the processing

Nov 21 '05 #3
CS,

What is than the difference with this sentence in my idea it is in this case
exactly the same

If (curName.Compar eTo(prevName)) <> 0 Then

(With corrected error, in your code are you testing agains an evaluation)

It is good to set Option Strict On in your program, this will than be showed
direct when you are making your code.

Cor
Nov 21 '05 #4
You've got your not equal to zero check in the wrong place.

The line should read:

If (curName.Compar eTo(prevName) <> 0) Then

That should fix your cast exception error.

Hope this helps,
Brian Swanson

"cs*****@yahoo. com" <cs*****@yahoo. com> wrote in message
news:cs*****@ya hoo.com:
I am getting an invalid cast exception - cast from string to type
double is not valid.

Dim curName As String
Dim prevName As String = ""
curName = CStr(rows.Item( i).Item(colSchN ame)) ' extract name from
database row
If (curName.Compar eTo(prevName <> 0)) Then <--- exception occurs on
this line

I do a cast on line 3 but that is not the one getting an exception. Any
help appreciated...c harlie


Nov 21 '05 #5
Hi CS,

the closing braket is at the wrong place, so you compare prevName to 0

If (curName.Compar eTo(prevName) <> 0)
^

Roland

"cs*****@yahoo. com" wrote:
I am getting an invalid cast exception - cast from string to type
double is not valid.

Dim curName As String
Dim prevName As String = ""
curName = CStr(rows.Item( i).Item(colSchN ame)) ' extract name from
database row
If (curName.Compar eTo(prevName <> 0)) Then <--- exception occurs on
this line

I do a cast on line 3 but that is not the one getting an exception. Any
help appreciated...c harlie

Nov 21 '05 #6
Thanks - obviously I didn't see that.

Nov 21 '05 #7

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

Similar topics

3
13895
by: Giulio Santorini | last post by:
Hi, I've got a little problem with my C# WinForms test application. I would like to have a ComboBox showing a a visual value and some hidden values. So I build a class able to store thoose values. This class called ListItem have got two private variable, one is a string containing the visual value, the other one is a UDT variable. It is a struct called
0
1688
by: Alan Z. Scharf | last post by:
Win Server 2003 VS.Net 2003 --------------- 1. I'm having the same problem below on all six of my pages with a datagrid item. 2. These pages all worked fine for months until problem started. 3. Same problem on two different computers running Win 2003.
5
3447
by: Nick Flandry | last post by:
I'm running into an Invalid Cast Exception on an ASP.NET application that runs fine in my development environment (Win2K server running IIS 5) and a test environment (also Win2K server running IIS 5), but fails on IIS 6 running on a Win2003 server. The web uses Pages derived from a custom class I wrote (which itself derives from Page) to provide some common functionality. The Page_Load handler the failing webpage starts out like this: ...
3
2296
by: John Howard | last post by:
Making the following call to a local MSAccess database works fine: Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs) Dim intRows As Integer Dim strSQL As String Dim ds As New DataSet ' Create connection Dim cn As New OleDbConnection With cn .connectionstring =
1
4921
by: Hifni Shahzard | last post by:
Hi, I got a stored procedure, where it returns a value. But if I execute it. It gives an error as "Invalid cast from System.Int32 to System.Byte.". To make clear how do I execute this, below I'm specifiying my code: The Code used in Visual Studio: Function GetRank(ByVal ID As Integer, ByVal Comp As String, ByVal Sec As String, ByVal iDate As Date) As String 'Dim Ret As Integer
9
2214
by: buzz | last post by:
I am attempting to pass data between two asp.net web forms pages. I have found the method to do this on the msdn site here: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconPassingServerControlValuesBetweenPages.asp After attempting to do this myself, I kept getting an Invalid Cast Exception error, so I finally resorted to simply copying and pasting the MS code in this article into two pages for the...
15
2266
by: David | last post by:
Hi, I have built a web application that will be a very high profile application. We had tested it, demonstrated it and shown that it all works. On a dress rehearsal run through, it failed spectacularly. I was so embarrassed and felt like killing the person that made it fail. However, when it goes live, IT MUST NOT FAIL. The system has a backoffice system that takes an excel spreadsheet from the
7
3634
by: Chris Thunell | last post by:
I'm trying to loop through an exchange public folder contact list, get some information out of each item, and then put it into a vb.net datatable. I run though the code and all works fine until i get to item 250 i get a "system.invalid cast exception" and "specified cast is not valid". Once i get this error and try to go to the next record.. every record after gets the same error... It's like the com connection to outlook has been lost....
11
2593
by: batmanfreeze | last post by:
I am using C# in .Net 1.1, and need to access the 'Client' Property of TcpClient, so I created a derived class to do this based upon the Microsoft Sample, located at: http://msdn2.microsoft.com/en-us/library/system.net.sockets.tcpclient.client(VS.71).aspx The only problem is that in my main app, when I try to do the following, I get an Invalid Cast Exception: int PortNum = 10000; TcpListener objTcpListen = new...
0
9892
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
9735
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10997
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10661
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...
0
10347
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...
1
7889
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7067
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
5731
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4542
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.