ViewState Question

  • Thread starter Sparky Arbuckle
  • 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.
 
J

Jeffrey Palermo

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
 
K

Ken Dopierala Jr.

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.
 
S

Sparky Arbuckle

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.
 

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

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,054
Latest member
LucyCarper

Latest Threads

Top