473,769 Members | 2,382 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 2613
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
13886
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
1685
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
3436
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
2291
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
4905
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
2201
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
2255
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
3628
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
2588
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
10210
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
10043
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
9990
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
9861
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
8869
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...
1
7406
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
5298
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...
0
5446
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2814
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.