Solved

Why is my code not working?

Posted on 2004-10-13
15
228 Views
Last Modified: 2012-08-13
Seems to be a simple enough problem but I am unable to get the correct results. The erring line is as below:

<input TYPE="radio" NAME="ReleaseToProduction" value="0" <%if ((myRS("Release")=0) or (Trim(myRS("Release")) = "") or isNull(myRS("Release"))) then Response.Write "checked" end if%> >No

Its giving me the error

Microsoft VBScript runtime error '800a000d'

Type mismatch: '[string: " "]'

Please help!!

A.
0
Comment
Question by:arunatata
  • 5
  • 4
  • 3
  • +3
15 Comments
 
LVL 5

Expert Comment

by:waelothman
ID: 12303840
<input TYPE="radio" NAME="ReleaseToProduction" value="0" <%if ((myRS("Release")="") or (Trim(myRS("Release")) = "") or isNull(myRS("Release"))) then Response.Write "checked" end if%> >No

myRS("Release") seems to be string
0
 
LVL 5

Expert Comment

by:waelothman
ID: 12303847
you can't compare string with numeric (0)
0
 
LVL 15

Expert Comment

by:Colosseo
ID: 12303858
Hi

try with quotes around the 0 like so

<input TYPE="radio" NAME="ReleaseToProduction" value="0" <%if ((myRS("Release")="0") or (Trim(myRS("Release")) = "") or isNull(myRS("Release"))) then Response.Write "checked" end if%> >No

as 0 it is an integer but as "0" it is a string

HTH

Scott
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:arunatata
ID: 12303908
I did that with another - using value="1" - and that worked. For some reason it doesn't like the value " " in the database. If I have 0 or 1 or Null in the database it works fine...only for the spaces or blanks it has problems.

A.
0
 

Author Comment

by:arunatata
ID: 12303918
I tried with the quotes around the "0" and that didn't work either.
0
 
LVL 5

Expert Comment

by:waelothman
ID: 12304053
<input TYPE="radio" NAME="ReleaseToProduction" value="0" <%if ((cint(myRS("Release"))=0) or (Trim(myRS("Release")) = "") or isNull(myRS("Release"))) then Response.Write "checked" end if%> >No
0
 

Author Comment

by:arunatata
ID: 12304080
Not that either. As i mentioned in my post above - the problem is with the blank spaces - not the 0 or 1 or Null values in the database. I've verified with all three and only the spaces is giving me an error.
0
 
LVL 5

Assisted Solution

by:waelothman
waelothman earned 150 total points
ID: 12304222
it is not in database  ASp not allow you to compare string with number
 myrec("fieldname") always catched as string even if the field is numeric
0
 
LVL 10

Expert Comment

by:m8rix
ID: 12304336
Hi arunatata,

waelothman is correct, you can't compare string with numeric (0) however here is some code to replace what you currently have, it is a bit longer, but it is the only way... and it WILL fix your problem.

Cheers!

<%
strdatabase = " "
IsZero = false
If isNumeric(strdatabase) Then
      If strdatabase = 0 Then IsZero = true
End If
%>
<input TYPE="radio" NAME="ReleaseToProduction" value="0" <%if (IsZero) or (Trim(strdatabase) = "") or (isNull(strdatabase)) then Response.Write "checked" end if%> >No
0
 
LVL 10

Accepted Solution

by:
m8rix earned 350 total points
ID: 12304350
Oops! sorry arunatata, I posted you the code that I used for testing... here is the modified version of your code:

<%
IsZero = false
If isNumeric(myRS("Release")) Then
      If myRS("Release") = 0 Then IsZero = true
End If
%>
<input TYPE="radio" NAME="ReleaseToProduction" value="0" <%if (IsZero) or (Trim(myRS("Release")) = "") or isNull(myRS("Release"))) then Response.Write "checked" end if%> >No
0
 

Author Comment

by:arunatata
ID: 12304427
Nope - that doesn't work either. I am posting the entire page below - maybe something here will strike out as wrong..


<%@ Language=VBScript %>
<%Response.Buffer = "true"%>
<html>
<head>
<meta NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
</head>
<body>
<form action="SearchResultsUpdateData.asp" Method="Post" id="form5" name="form5">
<%
PONumber = Request("PONumber")
Output = Request("Output")
Key1 = request("Key1")

Dim myConn                  
Dim myRS                  
Dim myRS1
Dim stmt            
Dim DText            
Dim i            

Set myRS = Server.CreateObject("ADODB.Recordset")
Set myRS1= Server.CreateObject("ADODB.Recordset")
Set myConn = Server.CreateObject("ADODB.Connection")
DText="Provider=SQLOLEDB;Server=abc;Initial Catalog=sand;User ID=sa"
myConn.Open DText
stmt1 = "select * from DesignMain where [PO Number] = '"&PONumber&"'"      
myRS1.Open stmt1, myConn,1,3
stmt = "Select * from BoardDesignYN where [PO Number] = '"&PONumber&"'"
myRS.Open stmt,myConn,1,3

IsZero = False

if isNumeric(myRS("Release to Production")) then
      if myRS("Release to Production") = 0 then
           IsZero = True
      end if
end if
%>


<td><b>Net List</b>
<input TYPE="radio" NAME="NetList" value="1" <%if (myRS("Net List"))=1 then Response.Write "Checked" end if%>>Yes
<input TYPE="radio" NAME="NetList" value="0" <%if (myRS("Net List"))=0 then Response.Write "Checked" end if%>>No</td>
</tr><br>
<% 'The section above works fine. I didn't have to go through any integer or string conversions for this.

'The section below is the problem area.
%>


<td><b>Release to Production?</b>
<input TYPE="radio" NAME="Release" value="1" <%if (myRS("Release To Production"))=1 then Response.Write "Checked" end if%>>Yes
<input TYPE="radio" NAME="Release" value="0" <%if ((IsZero) or (Trim(myRS("Release to Production")) = "") or isNull(myRS("Release to Production"))) then Response.Write "checked" end if%>>No
</td>
</tr>




<tr><td align="center" colspan="2"><input TYPE="submit" VALUE="Update" id="submit" name="submit"></td></tr>


</table>

<%      
myRS.Close
set myRS=nothing
%>


</table>



</form>

</body>
</html>
0
 
LVL 10

Expert Comment

by:m8rix
ID: 12304814
Ok forget what I suggested before, try replacing this WHOLE section:

<td><b>Net List</b>
<input TYPE="radio" NAME="NetList" value="1" <%if (CStr(myRS("Net List"))="1") then Response.Write "Checked" end if%>>Yes
<input TYPE="radio" NAME="NetList" value="0" <%if (Cstr(myRS("Net List"))="0") then Response.Write "Checked" end if%>>No</td>
</tr><br>
<% 'The section above works fine. I didn't have to go through any integer or string conversions for this.

'The section below is the problem area.
%>


<td><b>Release to Production?</b>
<input TYPE="radio" NAME="Release" value="1" <%if (CStr(myRS("Release To Production"))="1") then Response.Write "Checked" end if%>>Yes
<input TYPE="radio" NAME="Release" value="0" <%if (CStr(myRS("Release to Production"))="1") or (Trim(CStr(myRS("Release to Production"))) = "") or isNull(myRS("Release to Production")) then Response.Write "checked" end if%>>No
</td>
</tr>
0
 
LVL 26

Expert Comment

by:Rejojohny
ID: 12305392
what is the datatype of field "release to production" and try len(trim(myRs("Release to production")) = 0 instead of ltrim(myRs("Release to production") = ""
0
 
LVL 3

Expert Comment

by:Kupi
ID: 12305913
What about this?

<input TYPE="radio" NAME="ReleaseToProduction" value="0" <%If CInt("0" & Trim(myRS("Release"))) = 0 Then Response.Write "checked" End If%>>No

This combines all your conditions (= 0, = "", = NULL) in one.

Kupi
0
 
LVL 5

Expert Comment

by:waelothman
ID: 12306364
please     if myRS("Release to Production") = "0" then
as well as in all code
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question