Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HELP! reducing the quantity value of db field prob!!

Status
Not open for further replies.

tuam1234

Technical User
Feb 6, 2004
52
IE
if someone could see what im doin wrong id really appreciate it!!!

in the code below im trying to reduce the value of the "Quant" field by 1 in the Holidays database.. the prob is the it will display the new reduced value on the screen BUT it wont update it in the database, it remans unchanged...

the problem is in the bottom of this code:

<%

'Dimension variables
Dim connection
Dim check
Dim data
Dim insert
Dim query


Set connection = Server.CreateObject("ADODB.Connection")

connection.Open("credit")

Set data = Server.CreateObject("ADODB.RecordSet")

query = "SELECT * FROM credInfo"
data.CursorType=2
data.LockType=3
data.Open query, connection
data.AddNew

data.Fields("fullname")= Request("fullname")
data.Fields("add1")= Request("add1")
data.Fields("add2")= Request("add2")
data.Fields("email")= Request("email")
data.Fields("cardType")= Request("cardType")
data.Fields("cardNum")= Request("cardNum")
data.Fields("cardExpiryMonth")= Request("cardExpiryMonth")
data.Fields("cardExpiryYear")= Request("cardExpiryYear")
data.Fields("totalPrice")= Request("totalPrice")
data.Update
%><%
'Dimension variables
Dim conn
Dim check1
Dim data1
Dim insert1
Dim query1
Dim newQuant
Dim oldQuant

Set conn = Server.CreateObject("ADODB.Connection")

conn.Open("auction1")

Set data1 = Server.CreateObject("ADODB.RecordSet")

query1 = "SELECT Quant FROM Holidays"
data1.CursorType=2
data1.LockType=3
data1.Open query1, conn

oldQuant = CStr (Request("Quant"))
newQuant = (insert1 & (oldQuant) - 1)
data1.Fields("Quant")= newQuant
data1.Update

data1.Close()
data.Close()
connection.Close()
conn.Close()
Response.Write(newQuant)

%> all replies welcome!
 
as is you are returning a column of records with this
query1 = "SELECT Quant FROM Holidays"

Form what you've posted in detail, I think what you are looking for is
query1 = "SELECT MAX(Quant) FROM Holidays"
or
query1 = "SELECT MAX(Quant) FROM Holidays WHERE it = something"


as is the reason you are .write'ing only one value is you are at the beginning of the array constructed by the query. (the top of the Quant column)



___________________________________________________________________

The answer to your ??'s may be closer then you think.
Check out Tek-Tips knowledge bank by clicking the FAQ link at the top of the page
 
that should ahve been

query1 = "SELECT Quant FROM Holidays WHERE it = something"

___________________________________________________________________

The answer to your ??'s may be closer then you think.
Check out Tek-Tips knowledge bank by clicking the FAQ link at the top of the page
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top