Wrox Programmer Forums
|
ASP Forms As of Oct 5, 2005, this forum is now locked. Please use "Classic ASP beginner" at http://p2p.wrox.com/forum.asp?FORUM_ID=54 or "Classic ASP Professional" http://p2p.wrox.com/forum.asp?FORUM_ID=56 instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP Forms section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 6th, 2005, 09:18 AM
Authorized User
 
Join Date: Sep 2003
Posts: 81
Thanks: 0
Thanked 0 Times in 0 Posts
Default Still in Trouble with that "0"

I am still trying to replace a NULL or "" in a Numeric field with a Zero

The first part check out it seems

<% pregroup = rs("pregroup")
 if pregroup <> "" then
 pregroup = pregroup
 else
   pregroup ="0"
 end if
 response.write pregroup
 %>

The response.write gives me my zero when the field is empty or whatever was in the field if it was not empty

However I then want to insert the Numeric value I have just seen into a form where I am updating all the other fields using

<form method="post" action="lmadmin3.asp?Actionvar=update">
<label for="br_no">BR.Number</label>
<input id="br_no" name="br_no" value=" <% =rs("br_no") %>" />
<br />
<label for="other_no">LMS No.</label>
<input id="other_no" name="other_no" value=" <% =rs("other_no") %>" />
<br />
<label for="pregroup">Pre-Group No.</label>

This next line I cannot get right

  <input id="Pregroup" name="Pregroup" />
  <br />

I have also tried variations on this attempt

<input id="other_no" name="other_no" value=" <% =rs("other_no") %>"

Some guidence as to what I need here to get the result in the Form so I can see if it has a valid number or is a Zero, and allow an update of the record at the end

Please someone ...

Topshed
 
Old February 7th, 2005, 12:50 AM
Friend of Wrox
 
Join Date: May 2004
Posts: 642
Thanks: 0
Thanked 43 Times in 42 Posts
Default

I am not clear what is exactly needed, but if you want to check for Pregroup is a valid number or not then you can use isnumeric() function.

If you want to check for null, then u can use isnull() function.





Om Prakash
 
Old February 7th, 2005, 01:48 AM
Authorized User
 
Join Date: Sep 2003
Posts: 81
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yup, I am aware of the options, but my Problem is then getting the result to show in my Form after I have checked and manipulated it.
I want the 0 or the existing number is to show in this form below so i can update to the new value on submit


<p>Update</p>
<% pregroup = rs("pregroup")
 if pregroup <> "" then
 pregroup = pregroup
 else
   pregroup ="0"
 end if
 response.write pregroup
 %>
<form method="post" action="lmadmin3.asp?Actionvar=update">
  <label for="lclas">Class 1</label>
  <input id="lclas" name="lclas" value=" <% =rs("lclas") %>" />
  <br />
  <label for="class2">Class 2</label>
  <input id="class2" name="class2" value=" <% =rs("class2") %>" />
  <br />

*****This bit does not weork ******************

  <label for="pregroup">Pre-Group No.</label>
  <input id="pregroup" name="pregroup" value=" <% =rs("pregroup") %>" />
  <br />

************************************************** *********************
  <label for="br_no">BR.Number</label>
  <input id="br_no" name="br_no" value=" <% =rs("br_no") %>" />
  <br />
  <label for="other_no">LMS No.</label>
  <input id="other_no" name="other_no" value=" <% =rs("other_no") %>" />
  <br />
  <label for="wheel">Wheel Arrangement</label>
  <input id="wheel" name="wheel" value=" <% =rs("wheel") %>" />
  <br />
  <label for="cme">CME</label>
  <input id="cme" name="cme" value=" <% =rs("cme") %>" />
  <br />
  <label for="loco_name">Loco Name</label>
  <input id="loco_name" name="loco_name" value=" <% =rs("loco_name") %>" />
  <br />
  <label for="builder">Builder</label>
  <input id="builder" name="builder" value=" <% =rs("builder") %>" />
  <br />
  <label for="build_no">Build Number</label>
  <input id="build_no" name="build_no" value=" <% =rs("build_no") %>" />
  <br />
  <label for="mm_build">Build Month</label>
  <input id="mm_build" name="mm_build" value=" <% =rs("mm_build") %>" />
  <br />
  <label for="yy_build">Build Year</label>
  <input id="yy_build" name="yy_build" value=" <% =rs("yy_build") %>" />
  <br />
  <label for="mm_wdn">Withdrawn Month</label>
  <input id="mm_wdn" name="mm_wdn" value=" <% =rs("mm_wdn") %>" />
  <br />
  <label for="yy_wdn">Withdrawn Year</label>
  <input id="yy_wdn" name="yy_wdn" value=" <% =rs("yy_wdn") %>" />
  <br />
  <label for="code">Shed Code</label>
  <input id="code" name="code" value=" <% =rs("code") %>" />
  <br />
  <label for="last_shed">Last Shed</label>
  <input id="last_shed" name="last_shed" value=" <% =rs("last_shed") %>" />
  <br />
  <label for="mm_cut">Month Cut</label>
  <input id="mm_cut" name="mm_cut" value=" <% =rs("mm_cut") %>" />
  <br />
  <label for="yy_cut">Year Cut</label>
  <input id="yy_cut" name="yy_cut" value=" <% =rs("yy_cut") %>" />
  <br />
  <label for="">Cut by / Fate</label>
  <input id="cut" name="cut" value=" <% =rs("cut") %>" />
  <br />
  <label for="notes">Notes</label>
  <input id="notes" name="notes" value=" <% =rs("notes") %>" />
  <br />
  <input type="hidden" name="flag" value="2" />
  <input type="hidden" name="Recordid" value="<%=rs("ID")%>" />
  <br />
  <label for="submit">label</label>
  <input type="submit" value="Submit Change" />
</form>
<br />
<%
      rs.MoveNext
      rs.Close
    END IF
  ELSEIF Request.Form("flag")="2" THEN
'pre_var = rs("pregroup")
'if isnull(rs("pregroup")) then
' rs("pregroup") = 0
' response.write rs("pregroup")
'else
' prs("pregroup")=rs("pregroup")
' response.write rs("pregroup")
'end if
'response.end
   SQLstmt = "UPDATE lms SET "
   SQLstmt = SQLstmt & "lclas='" & TRIM(Request.Form("lclas")) & "', "
   SQLstmt = SQLstmt & "class2='" & TRIM(Request.Form("class2")) & "', "
   SQLstmt = SQLstmt & "pregroup='" & TRIM(Request.form("pregroup")) & "', "
   SQLstmt = SQLstmt & "br_no='" & TRIM(Request.Form("br_no")) & "', "
   SQLstmt = SQLstmt & "other_no='" & TRIM(Request.Form("other_no")) & "', "
   SQLstmt = SQLstmt & "wheel='" & TRIM(Request.Form("wheel")) & "', "
   SQLstmt = SQLstmt & "cme='" & TRIM(Request.Form("cme")) & "', "
   SQLstmt = SQLstmt & "loco_name='" & TRIM(Request.Form("loco_name")) & "', "
   SQLstmt = SQLstmt & "builder='" & TRIM(Request.Form("builder")) & "', "
   SQLstmt = SQLstmt & "build_no='" & TRIM(Request.Form("build_no")) & "', "
   SQLstmt = SQLstmt & "mm_build='" & TRIM(Request.Form("mm_build")) & "', "
   SQLstmt = SQLstmt & "yy_build='" & TRIM(Request.Form("yy_build")) & "', "
   SQLstmt = SQLstmt & "mm_wdn='" & TRIM(Request.Form("mm_wdn")) & "', "
   SQLstmt = SQLstmt & "yy_wdn='" & TRIM(Request.Form("yy_wdn")) & "', "
   SQLstmt = SQLstmt & "code='" & TRIM(Request.Form("code")) & "', "
   SQLstmt = SQLstmt & "last_shed='" & TRIM(Request.Form("last_shed")) & "', "
   SQLstmt = SQLstmt & "mm_cut='" & TRIM(Request.Form("mm_cut")) & "', "
   SQLstmt = SQLstmt & "yy_cut='" & TRIM(Request.Form("yy_cut")) & "', "
   SQLstmt = SQLstmt & "cut='" & TRIM(Request.Form("cut")) & "', "
   SQLstmt = SQLstmt & "notes='" & TRIM(Request.Form("notes")) & "' "
   SQLstmt = SQLstmt & " WHERE ID=" & TRIM(Request.Form("Recordid"))
    %>
SQL statement: <%=SQLstmt%>
<%
    Conn.Execute (SQLstmt)
    Response.Write "Operation Complete<br /><A HREF=""lmadmin3.asp"">Home</A>"
  END IF </i>

 
Old February 7th, 2005, 06:19 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

If it is a number you should use a numeric datatype in your db table, then you could never get "" in there. but anyway, you want
Code:
If Len("" & rs("pregroup")) = 0 Then
    pregroup = 0
Else
    pregroup = rs("pregroup")
End If
...
<input id="pregroup" name="pregroup" value="<%=pregroup%>" /> USE THE VARIABLE HERE NOT THE rs("pregroup")
...
hth
Phil
 
Old February 9th, 2005, 08:03 PM
Authorized User
 
Join Date: Sep 2003
Posts: 81
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you both so much for your help, The number is a numeric field
I was stufing around trying all sorts to come up with an answer.
Final code I am using that works great...

<% pregroup = rs("pregroup")
 if isnull(pregroup) then
   pregroup = 0
 else
   pregroup = pregroup
 end if
>
>
>
<input id="pregroup" name="pregroup" value="<%=pregroup%>" />

ect;...

Thanks Topshed

 
Old February 10th, 2005, 02:12 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

The easiest way is to do the replacing of NULL to 0 in your SQL, a stored procedure would be best.





Similar Threads
Thread Thread Starter Forum Replies Last Post
If Else Trouble Cibressus Beginning PHP 0 May 1st, 2007 02:04 PM
Newbie having trouble. Please help!!!!! crittag ASP.NET 2.0 Basics 0 June 24th, 2006 05:00 PM
SQL Trouble mrideout BOOK: Beginning ASP.NET 1.0 1 September 30th, 2004 12:24 PM
Please i have had a Trouble hurted Wrox Book Feedback 1 June 28th, 2004 02:18 AM
trouble databass Classic ASP Databases 2 August 16th, 2003 10:27 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.