ViewState Question

  • Thread starter Thread starter Sparky Arbuckle
  • Start date Start date
S

Sparky Arbuckle

What is wrong with the following syntax?


IF ViewState("CustID") < " " AND gtCart.Count > " " THEN WriteOrder()

The error I get is:

Exception Details: System.FormatException: Input string was not in a
correct format.
 
Sparky,
Honestly, it could be any number of things. ViewState indexers return
an object, so I would recommend casting it to the expected type before
using, and Count ( I assume ) is an integer, so you have an issue
there, but the exception could have come from the WriteOrder method.
Did you examine the stack trace to determine where the exception came
from? A little debugging and stepping through the code can give you
the exact statement that caused the exception.

Best regards,
Jeffrey Palermo
Blog: http://www.jeffreypalermo.com
 
Hi,

Maybe try this:

If (CStr(ViewState("CustID")).Length > 0) AND (gtCart.Count > 0) Then
WriteOrder()

You appear to be mixing integers and strings. Is the Count property of
gtCart an integer? If so, then the above will work. If it is a string
exchange this: (CStr(gtCart.Count).Length > 0) with this: (gtCart.Count >
0) . Then you should be good to go. Also, put Option Explicit On at the
top of your code file and in VS.Net it should highlight where you are making
dangerous conversions between types. Good luck! Ken.
 
InvalidCastException: Cast from string "" to type 'Double' is not valid

I found that from the stack trace. How do I actually use the stack
trace? That would probably be great information.
 
Back
Top