PDA

View Full Version : validation question


rthewissen
10-06-2005, 09:13 PM
Hello all,

I'm pulling a piece of date from a SQL stored procedure. I also wanted to format the display in currency view.


This is what Dreamweaver created.



<%# Double.Parse(Procedure1.ParameterValue("@panelsum").ToString()).ToString("C")%></p>


it works fine if the @panelsum actually contains something. However I get error codes when its not.

Anyone know how I can tie this to a conditional statement?


Thanks :blink:

davidj
10-07-2005, 11:40 AM
please supply error codes

rthewissen
10-07-2005, 01:36 PM
Here you go :|

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 31: <% Session("loginname")="rthewissen" %>
Line 32:

Testing Variables</p>
Line 33:

<%# Double.Parse(Procedure1.ParameterValue("@panelsum").ToString()).ToString("C") %></p>
Line 34: </body>
Line 35: </html>


Source File: c:\inetpub\wwwroot\flash\sptest.aspx Line: 33

Stack Trace:


[FormatException: Input string was not in a correct format.]
System.Number.ParseDouble(String s, NumberStyles style, NumberFormatInfo info) +0
System.Double.Parse(String s, NumberStyles style, IFormatProvider provider) +208
System.Double.Parse(String s) +12
ASP.sptest_aspx.__DataBind__control13(Object sender, EventArgs e) in c:\inetpub\wwwroot\flash\sptest.aspx:33
System.Web.UI.Control.OnDataBinding(EventArgs e) +66
System.Web.UI.Control.DataBind() +26
System.Web.UI.Control.DataBind() +86
DreamweaverCtrls.PageBind.Page_Load(Object src, EventArgs E)
System.Web.UI.Control.OnLoad(EventArgs e) +67
System.Web.UI.Control.LoadRecursive() +35
System.Web.UI.Control.LoadRecursive() +98
System.Web.UI.Page.ProcessRequestMain() +750

Basically when the return variable @panelsum has a return value the whole thing works. However, when the stored procedure returns nothing for @panelsum, the formating causes the error. If I remove the currency formatting, then I do not get an error.

I'd like to use the currency formatting if possible.


Thanks for any assistance.



Rich T.

davidj
10-07-2005, 01:59 PM
i have never touched stored procedures but looking at it...

<%# Double.Parse(Procedure1.ParameterValue("@panelsum" ).ToString()).ToString("C")%>


cant you validate it like this

<%#

IF (@panelsum !='')

Double.Parse(Procedure1.ParameterValue("@panelsum" ).ToString()).ToString("C")

END IF

%>

before you Double.Parse the string can you not validate it first

rthewissen
10-07-2005, 03:48 PM
When I changed the code to the one you supplied, I get a compiler error message: BC30201: Expression Expected

Line 33 is displayed in red


Line33:

<%# IF (@panelsum !='')




I am new at all this stuff. I'll try and see if I can validate the output prior to exiting the stored procedure and substitute a value if it is empty

Rich T.

rthewissen
10-07-2005, 05:20 PM
Hi,

I added the following lines to my stored procedure:

IF @panelsum is null
Begin
set @panelsum=0.00
End


The following line now works

<%# Double.Parse(Procedure1.ParameterValue("@panelsum").ToString()).ToString("C") %></p>


The problem is that currency formating needed something, if the returned value blank, it would error out.

By setting a default value in the SQL stored procedure, cleared the issue.

I'd still like to know how to set the value in aspx.


thanks :)


Rich T.