Cast incorrect

Discussion in 'ASP .Net' started by tshad, Feb 3, 2006.

  1. tshad

    tshad Guest

    I have a field that I read from my database that is a bit field field into a
    textbox.

    The Trace on the variable (MyInfoCreated) shows it as "False" - as you can
    see from the error.

    I tried it with:

    if not MyinfoCreated then

    as well as what is shown here

    if (MyInfoCreated.Text <> 1) then

    The first says it Cast from "False" to Long is invalid and the second says
    the Cast from "False to Double is invalid.

    If I do:

    If MyInfoCreated.Text then

    This works fine.

    The error I get is:

    ********************************************************************
    Input string was not in a correct format.
    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.FormatException: Input string was not in a correct
    format.

    Source Error:


    Line 219: else
    Line 220:trace.warn("MyInfoCreated.Text = " & MyInfoCreated.Text)
    Line 221: if (MyInfoCreated.Text <> 1) then
    Line 222:s.close()
    Line 223: response.Redirect("secure/MyInformation.aspx")


    Source File: C:\Inetpub\wwwroot\staffingworkshop\applicant\EELogin.aspx
    Line: 221

    Stack Trace:


    [FormatException: Input string was not in a correct format.]
    Microsoft.VisualBasic.CompilerServices.DoubleType.Parse(String Value,
    NumberFormatInfo NumberFormat) +195
    Microsoft.VisualBasic.CompilerServices.DoubleType.FromString(String
    Value, NumberFormatInfo NumberFormat) +82

    [InvalidCastException: Cast from string "False" to type 'Double' is not
    valid.]
    Microsoft.VisualBasic.CompilerServices.DoubleType.FromString(String
    Value, NumberFormatInfo NumberFormat) +171
    Microsoft.VisualBasic.CompilerServices.DoubleType.FromString(String
    Value) +7
    ASP.EELogin_aspx.Login() in
    C:\Inetpub\wwwroot\staffingworkshop\applicant\EELogin.aspx:221
    ****************************************************************************************

    Thanks,

    Tom
    tshad, Feb 3, 2006
    #1
    1. Advertising

  2. tshad

    sloan Guest

    You've been writing too much asp or vb6 code.


    Try this:

    if (MyInfoCreated.Text.Length > 0) then

    if ( Convert.ToBoolean (MyInfoCreated.Text ) = Convert.ToBoolean (
    )) then

    end if

    Even that isn't really good code.

    You have 3 things.
    TextBox
    TextBox.Text (string)
    1 (number)

    You need to convert things to booleans to try and compare them that way.

    A TextBox is not a TextBox.Text (string) nor is it a number 1.

    ...


    "tshad" <> wrote in message
    news:...
    > I have a field that I read from my database that is a bit field field into

    a
    > textbox.
    >
    > The Trace on the variable (MyInfoCreated) shows it as "False" - as you can
    > see from the error.
    >
    > I tried it with:
    >
    > if not MyinfoCreated then
    >
    > as well as what is shown here
    >
    > if (MyInfoCreated.Text <> 1) then
    >
    > The first says it Cast from "False" to Long is invalid and the second says
    > the Cast from "False to Double is invalid.
    >
    > If I do:
    >
    > If MyInfoCreated.Text then
    >
    > This works fine.
    >
    > The error I get is:
    >
    > ********************************************************************
    > Input string was not in a correct format.
    > 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.FormatException: Input string was not in a

    correct
    > format.
    >
    > Source Error:
    >
    >
    > Line 219: else
    > Line 220:trace.warn("MyInfoCreated.Text = " & MyInfoCreated.Text)
    > Line 221: if (MyInfoCreated.Text <> 1) then
    > Line 222:s.close()
    > Line 223: response.Redirect("secure/MyInformation.aspx")
    >
    >
    > Source File: C:\Inetpub\wwwroot\staffingworkshop\applicant\EELogin.aspx
    > Line: 221
    >
    > Stack Trace:
    >
    >
    > [FormatException: Input string was not in a correct format.]
    > Microsoft.VisualBasic.CompilerServices.DoubleType.Parse(String Value,
    > NumberFormatInfo NumberFormat) +195
    > Microsoft.VisualBasic.CompilerServices.DoubleType.FromString(String
    > Value, NumberFormatInfo NumberFormat) +82
    >
    > [InvalidCastException: Cast from string "False" to type 'Double' is not
    > valid.]
    > Microsoft.VisualBasic.CompilerServices.DoubleType.FromString(String
    > Value, NumberFormatInfo NumberFormat) +171
    > Microsoft.VisualBasic.CompilerServices.DoubleType.FromString(String
    > Value) +7
    > ASP.EELogin_aspx.Login() in
    > C:\Inetpub\wwwroot\staffingworkshop\applicant\EELogin.aspx:221
    >

    ****************************************************************************
    ************
    >
    > Thanks,
    >
    > Tom
    >
    >
    sloan, Feb 3, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?ISO-8859-15?Q?Stefan_Schw=E4rzler?=

    what's incorrect ALIAS

    =?ISO-8859-15?Q?Stefan_Schw=E4rzler?=, Aug 3, 2005, in forum: VHDL
    Replies:
    1
    Views:
    465
    Jonathan Bromley
    Aug 4, 2005
  2. Dominique Vandensteen

    date format incorrect

    Dominique Vandensteen, Oct 23, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    457
    Bret Mulvey [MS]
    Oct 24, 2003
  3. MSG

    to cast or not to cast malloc ?

    MSG, Feb 6, 2004, in forum: C Programming
    Replies:
    38
    Views:
    1,076
    Dan Pop
    Feb 10, 2004
  4. EvilRix
    Replies:
    8
    Views:
    640
    Martin Dickopp
    Feb 14, 2004
  5. Pavel
    Replies:
    7
    Views:
    527
    Pavel
    Sep 19, 2010
Loading...

Share This Page