how to check numeric value of field in database in asp using javascript and update

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dosa
    New Member
    • Mar 2013
    • 3

    how to check numeric value of field in database in asp using javascript and update

    hello
    the promblem is when i want decrement the value of field in database didn't work like this:

    copy=rs.fields( "num_copies").v alue;
    copy=copy-1;


    then i want update the value of field (num_copies) in database

    Code:
    <%@language="javascript"%>
     <!--#include file="connection.asp"-->
      <%
    
     
       RS.open("SELECT *FROM book_info where (num ="+Request.form("No_Book")+")and(title_book='"+Request.form("Book1")+"')",abCon);
    	if(!RS.EOF)
          {
    	   
    	    if( RS.fields("num_copies").value >1)
    	      {
    		  copy=RS.fields("num_copies").value;
    	       rent=RS.fields("Rent_book").value;
    	       copy=copy-1;
    		   rent=rent+1;
    		   RS.Fields("num_copies")=copy;
    		   RS.Fields("Rent_book")=rent;
    	       RS.Update;
              RS.Close;
             abCon.close;
    		
    	      }
         else
    	  {
    	    Response.write("There is no enogh copies of this book");
    	  
    	   RS.close;
    	   abCon.close;
    	   }
    	   }
       %>
    Last edited by Niheel; Mar 4 '13, 04:51 PM. Reason: merged description into first post
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    You haven't explained what problem you're having with your code.

    Comment

    • dosa
      New Member
      • Mar 2013
      • 3

      #3
      hello i want know how to do it my code is wrong

      Comment

      • VanessaMeacham
        New Member
        • Sep 2012
        • 31

        #4
        Hi Give the Clear Description that which kind of Problem you face with this code.

        Comment

        • Rabbit
          Recognized Expert MVP
          • Jan 2007
          • 12517

          #5
          Your Copy variable is only a copy of the data on the database. It is not linked to the value in the database itself.

          You will need to run an update query.

          Comment

          • sharmajv
            New Member
            • Apr 2013
            • 11

            #6
            Have u tried using

            Code:
            copy=rs.fields("num_copies").value;
            copy=CInt(copy)-1;

            Comment

            Working...