Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > .NET 1.0 and Visual Studio.NET > .NET Framework 1.x
|
.NET Framework 1.x For discussing versions 1.0 and 1.1 of the Microsoft .NET Framework.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the .NET Framework 1.x section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 12th, 2007, 09:27 AM
Registered User
 
Join Date: Aug 2007
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Cast from string 'OPEN' to type 'Double' is not va

Hi.. Please help me resolve this error "Cast from string 'OPEN' to type 'Double' is not valid.". Error here If CallStatus = 10 Then ....
Code:
Public Sub UpdateCallStatus()
        Dim CALLID, RequestorID, CommentsFromITD, MessageFromITD, MessageToITD, CallStatus, strSQL As String
        CALLID = Request.QueryString("CallID")
        RequestorID = Session("USER_ID")
        CommentsFromITD = lblcomments.Text
        MessageFromITD = lblmessage.Text
        MessageToITD = txt_desc.Text
        CallStatus = Trim(Request.Form(ddl_callstatus.UniqueID))

        Dim ObjCmd As SqlCommand
        Dim ObjDR As SqlDataReader

        Try
            If CallStatus = 10 Then
                strSQL = "UPDATE CALLS SET STATUS_ID=" & CallStatus & " WHERE CALL_ID= " & CALLID & ""
                ObjCmd = New SqlCommand(strSQL, ObjConn)
                ObjConn.Open()
                ObjDR = ObjCmd.ExecuteScalar()
                gbVariables.insertuserevents(CALLID, RequestorID, "Call Closed")
                Response.Redirect("UserCallClosed.aspx")
                ObjConn.Close()
            Else
                strSQL = "UPDATE CALLS SET STATUS_ID=" & CallStatus & " WHERE CALL_ID= " & CALLID & ""
                ObjCmd = New SqlCommand(strSQL, ObjConn)
                ObjConn.Open()
                ObjDR = ObjCmd.ExecuteScalar()
                ObjConn.Close()

                strSQL = "SELECT STATUS_LABEL FROM STATUS WHERE STATUS_ID = " & CallStatus & ""
                ObjCmd = New SqlCommand(strSQL, ObjConn)
                ObjConn.Open()
                ObjDR = ObjCmd.ExecuteScalar()
                ObjConn.Close()

                gbVariables.insertuserevents(CALLID, RequestorID, CallStatus)
                CallStatus = ""
            End If
        Catch ex As Exception
            lblmsg.Text = ex.Message.ToString
        End Try
    End Sub
Thanks...

 
Old August 12th, 2007, 12:45 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

You have declared CallStatus as a string. You are trying to test it against a number. The runtime can't do this because those types are not comparable.

.NET is a strongly typed language. When you compare type values, each values' type must be comparable to the other. If the types are not comparable then the runtime will convert expandable types to make a comparison. This works for things like an integer to a float because a integer can be implicitly converted to a float (mathematically speaking, a INT is also a FLOAT, but not the other way around).

Unfortunately, VB.NET allows you to ignore the strong typing of .NET by means of the "Option Strict" setting in files and projects. Therefore you need to do two things:

1) You should add the code "Option Strict On" in the files or set the "Option Strict" setting for the project as a whole (this is the better approach).

2) Declare CallStatus as a number type and convert it when you get it, like this:

Dim CallStatus As Integer
CallStatus = Integer.Parse(Trim(Request.Form(ddl_callstatus.Uni queID)))

Now, the test "CallStatus = 10" will work.

Here's an interesting article about Option Strict and Option Explicit:
http://www.codinghorror.com/blog/archives/000355.html

Also, for the details of these VB.NET features:
Option Strict
Option Explicit

-Peter





Similar Threads
Thread Thread Starter Forum Replies Last Post
Cast from string to type Double not valid mika27 ASP.NET 2.0 Basics 0 January 31st, 2007 05:52 AM
Cast from string "" to type 'Double' is not dounme ADO.NET 1 March 8th, 2005 01:31 PM
Cast from string "" to type 'Double' is not dounme SQL Server 2000 1 February 18th, 2005 01:44 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.