Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Comparing Numeric Values
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Comparing Numeric Values

 Post Reply Post Reply Page  <123>
Author
Misty View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 February 2002
Location: United States
Status: Offline
Points: 711
Post Options Post Options   Thanks (0) Thanks(0)   Quote Misty Quote  Post ReplyReply Direct Link To This Post Posted: 05 October 2004 at 4:49pm

If the error is true (if the certain AreaID already exists in the database), then it won't update the database. I want the AreaID for a certain city to be updated if the areaID is null.

CLng(Area) comes from Request.Form(selArea). It is a number (ex: 1, 24, 234). I am looking for a value in the field.

Let me show you my sql statement:

 'Build the sql query used to fill the select element
sql = "select * from City"
sql = sql & " where City= '" & City & "'"
sql = sql & " and State= '" & State & "'"

The City database has a field called AreaID (int). The AreaID is null. I want to update the areaID for each City that has a null value.

Does this make sense about what I'm trying to do?

Back to Top
Gullanian View Drop Down
Senior Member
Senior Member
Avatar

Joined: 04 January 2002
Location: England
Status: Offline
Points: 4373
Post Options Post Options   Thanks (0) Thanks(0)   Quote Gullanian Quote  Post ReplyReply Direct Link To This Post Posted: 05 October 2004 at 7:43pm
You get the BOF error because you are selecting a record that doesn't exist.

Put this in your code after you open rsCities:

If rsCities.EOF then  
    'Citiy doesn't exist in state
    Response.write(City & " in " & State & " does not exist in database")
Else
    'City does exist in DB
    Do your code if a city is found
End if
rsCities.close

Back to Top
Misty View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 February 2002
Location: United States
Status: Offline
Points: 711
Post Options Post Options   Thanks (0) Thanks(0)   Quote Misty Quote  Post ReplyReply Direct Link To This Post Posted: 06 October 2004 at 1:44am

I tried what you suggested. But I think that there's something else wrong.

I did a check on the sql statement.

Here's the result:

select * from City where City= 'Albany' and State= 'NY' which is right. I don't understand what may be wrong.

I also got an error message when I tried using cLNG. Here's the error message that I got: Invalid use of Null: 'CLng' . I really need to be able to compare both AreaID from the database and AreaID that comes from the form.

The AreaID field in the City database (SQL Server 2000) is int for the data type and 4 in length.

 



Edited by Misty
Back to Top
Gullanian View Drop Down
Senior Member
Senior Member
Avatar

Joined: 04 January 2002
Location: England
Status: Offline
Points: 4373
Post Options Post Options   Thanks (0) Thanks(0)   Quote Gullanian Quote  Post ReplyReply Direct Link To This Post Posted: 06 October 2004 at 7:27am
Try running the query in query manager.  As for the clng error, it's because the variable you put inside the brackets in cLng() is mandatory, there has to be a variable in it, and if there is, the variable has not been set if you are getting a null error.  Check the variable contains a value.
Back to Top
ljamal View Drop Down
Mod Builder Group
Mod Builder Group


Joined: 16 April 2003
Status: Offline
Points: 888
Post Options Post Options   Thanks (0) Thanks(0)   Quote ljamal Quote  Post ReplyReply Direct Link To This Post Posted: 06 October 2004 at 8:15am
Use the isNull statement for MSSQL to return the int value of your choice for areaID so that CLng always receives an int value. The syntax is:
ISNULL ( check_expression , replacement_value )
For example
select IsNull(AreaID, 0) from City where City = 'Albany' and state = 'NY'
If the value for AreaID was null than the value returned would be 0.
Back to Top
Misty View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 February 2002
Location: United States
Status: Offline
Points: 711
Post Options Post Options   Thanks (0) Thanks(0)   Quote Misty Quote  Post ReplyReply Direct Link To This Post Posted: 06 October 2004 at 12:31pm

I am very frustrated because I still cannot get to work this. I tried doing what Ijamal suggested. I got the following error message:

Item cannot be found in the collection corresponding to the requested name or ordinal. I will bold the line that got this error message. AreaID definitely exists in the City database.

   'Build the sql query used to fill the select element

    sql = "select IsNull(AreaID, 0) from City"

    sql = sql & " where City= '" & hidCity & "'"

    sql = sql & " and State= '" & hidState & "'"

                        

   

                        

 

  

       'Create a recordset

      set rsCity = Server.CreateObject("ADODB.Recordset")

      rsCity.Open sql, connectionString, adOpenDynamic, adLockOptimistic

     

    'Initalize Error

    Error = False

   

  If rsCity.EOF then  

    'Area doesn't exist in state

    Response.write(hidCity & " in " & hidState & " does not exist in database")

Else

    'Area does exist in DB

   

    'Check to see if the database already has this area

    If CLng(Area) = CLng(rsCity("AreaID")) then (where the error is)

   

 

   

    Error = True

   

 

    %>

 

<%

 

'Move to the next recordset

rsCity.MoveNext

 

 

If Error = False then 

 

      

Back to Top
Gullanian View Drop Down
Senior Member
Senior Member
Avatar

Joined: 04 January 2002
Location: England
Status: Offline
Points: 4373
Post Options Post Options   Thanks (0) Thanks(0)   Quote Gullanian Quote  Post ReplyReply Direct Link To This Post Posted: 06 October 2004 at 1:10pm
Get rid of the isnull in the query.

Change:
If CLng(Area) = CLng(rsCity("AreaID")) then (where the error is)

To

If isNull(Area) = False then
    If Clng(Area) = rsCity("AreaID") then
       'Do whatever, this point means that area var is equal to record in loop
    End if
End if

Back to Top
Misty View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 February 2002
Location: United States
Status: Offline
Points: 711
Post Options Post Options   Thanks (0) Thanks(0)   Quote Misty Quote  Post ReplyReply Direct Link To This Post Posted: 06 October 2004 at 1:45pm

Gullanian,

Thank you for the code! It almost worked. But there is still something wrong. I think that it has something to do with the line of code: If Clng(Area) = rsCity("AreaID") then. It is frustrating because it won't let me use CLng(rsCity("AreaID")).

I found out it would update the AreaID when I had the following code: 
If rsCity.EOF then
'Area doesn't exist in state
Response.write(hidCity & " in " & hidState & " does not exist in database") 
Else
'Move to the next recordset
rsCity.MoveFirst
rsCity("AreaID") = Area
rsCity.update
End If

But this is not acceptable for this case. I want the AreaID to be only updated if the AreaID for a certain city is null. Does anyone have any idea how I might be able to make sure that both Area (from the form) and AreaID (from the database) are the same.

Back to Top
 Post Reply Post Reply Page  <123>

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.