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
michael View Drop Down
Senior Member
Senior Member
Avatar

Joined: 08 April 2002
Location: United States
Status: Offline
Points: 4670
Post Options Post Options   Thanks (0) Thanks(0)   Quote michael Quote  Post ReplyReply Direct Link To This Post Posted: 06 October 2004 at 3:04pm
Don't get rid of IsNull, ljamal was right, it being the easiest option, you just need to set the field name as it had been combined in a function so

'Build the sql query used to fill the select element
sql = "select IsNull(AreaID, 0) from City"

should be

'Build the sql query used to fill the select element
sql = "select IsNull(AreaID, 0) as AreaID from City"
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 4:31pm

I still cannot get the AreaID to be updated. I am getting no error message. The sql statement that Michael gave me worked. Maybe there's something I don't notice. It should work, but I don't know what's wrong. I really need this code because I want the AreaID for a certain city to be only updated one time.

Here's my new code after I did what Michael suggested:

   'Build the sql query used to fill the select element

    sql = "select IsNull(AreaID, 0) as AreaID 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

     

 

    Error = True

 

 

 

'Move to the next recordset

rsCity.MoveFirst

 

 

If Error = False then 

 

      rsCity("AreaID") = Area

     

 

      rsCity.update

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

Joined: 08 April 2002
Location: United States
Status: Offline
Points: 4670
Post Options Post Options   Thanks (0) Thanks(0)   Quote michael Quote  Post ReplyReply Direct Link To This Post Posted: 06 October 2004 at 5:33pm
'Move to the next recordset

rsCity.MoveFirst

shouldn't that be MoveNext if you want to move to the next record set? This way it will go to the first one (maybe I am just missing something I am tired)
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 6:50pm

I changed it to rsCity.MoveNext, but it didn't update the AreaID for a certain city.

I wonder if this is a problem with SQL Server 2000. I am so frustrated. The code should work, but I don't know why it won't work.

 

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: 07 October 2004 at 1:24am

I decided to experiment with the code below. I did a check and both AreaID and Area have the right values. I think that it might have to do something with my if statements or SQL Server. But it didn't work because I got the following error message:

Microsoft OLE DB Provider for SQL Server error '80040e21'

Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done.

Here's the code that I tried to use:

   'Build the sql query used to fill the select element

    sql = "select IsNull(AreaID, 0) as AreaID 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

 

 

  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

     

 

'Move to the next recordset

rsCity.MoveFirst

 

 

 

      rsCity("AreaID") = Area

      rsCity.update

 

 

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: 11 October 2004 at 11:11pm

I still have not gotten this to work yet. I've performed other tests. I wish that I could send someone the 3 web pages with the code and the tables. I wonder if this would work on another SQL Server. It is very possible that there is a typo somewhere.

Would anyone here be willing to test this on another SQL Server?

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.