Cast incorrect

T

tshad

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
 
S

sloan

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.

...
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top