Wrox Home  
Search P2P Archive for: Go

  Return to Index  

asp_databases thread: update and select problem


Message #1 by lodris@m... on Mon, 28 May 2001 20:13:03
Cant seem to get this working its telling me theres an error on line 60---

pvariable = rs("LastTrade") 

but i have this exact same line on another page and it works fine .The 

error its giving me is this

ADODB.Field error '800a0bcd' 



Either BOF or EOF is True, or the current record has been deleted; the 

operation requested by the application requires a current record. 



/lodris-ca4/sellget.asp, line 60 

but i know that that field is populated cause i checked it

does anyone know whats wrong?

Thanks

Leigh







<%

  dim share,qleigh

 share = Request.QueryString("ShareOption")

qleigh = Request.QueryString("quantity")











  dim rst, conn, strSQL,rs6,rs1 ,rs2 ,rs3 ,rs4 ,rs5, pvariable, 

balvarialbe, newbal, costsofstock, qvariable

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

		conn.Open  "DSN=project; uid=lodris-ca4; pwd=lodris1141;"

set rst=server.CreateObject("ADODB.Recordset")

set rst = conn.execute  ("Select ShareOption, Quantity, Price, 

Date_bought, balance,sell_date,saleprice FROM sharesuser WHERE UserName 

= '" & Session("strLogin") & "' ") 



set rs = conn.execute("select LastTrade from trade where StockName = '" & 

share & "' AND (getday =  '"& Date &  "') ") 

pvariable = rs ("LastTrade") 





set rs1 = conn.execute("select balance from sharesuser where UserName = '" 

& Session("strLogin") & "' ") 

balvarialbe = rs1("balance") 

 

set rs5= conn.execute("select Quantity from sharesuser where ShareOption 

= '" & share & "'  ") 

qvariable = rs5 ("Quantity") 



costsofstock = (qleigh * pvariable )

updatebal = (balvarialbe + pvariable )

newquant =( qvariable - qleigh )



'Response.Write "balvarialbe="&(balvarialbe)&"<br>" 

'Response.Write "sharecost="&(sharecost)&"<br>" 

strSQL = ("UPDATE sharesuser SET balance = " & updatebal & " where 

UserName = '" & Session("strLogin") & "' ") 

strSQL1=("UPDATE sharesuser SET  quantity = " & newquant & " where 

UserName = '" & Session("strLogin") & "' ")

strSQL2 = ("INSERT INTO sharesuser (sell_date ,saleprice ) VALUES ( '" & 

now() & "' ," & pvariable & " )")

'Response.Write "strSQL ="&(strSQL)&"<br>" 

msg="Less then or equal to 0" 

msg2="True" 

msg3="cant sell" 

if cdbl(qleigh) <= 0 then 

Response.Write (msg) 

response.redirect "leigh7.html" 

elseif cdbl(qvariable) >= cdbl(qleigh) then 

Response.Write (msg2) 

set rs2=conn.execute(strSQL) 

set rs3=conn.execute(strSQL1) 

set rs4=conn.execute(strSQL2) 

else 

Response.Write (msg3) 

response.redirect "leigh7.html" 

end if 
Message #2 by "Ken Schaefer" <ken@a...> on Tue, 29 May 2001 16:56:08 +1000
How do you know you are returning any records? You *must* check for .EOF

before trying to access the recordset.



strSQL = _

    "SELECT LastTrade " & _

    "FROM Trade " & _

    "WHERE StockName = '" & share & "', " & _

    "AND GetDay = '" & Date & "'"

'

Set objRS = objConn.Execute strSQL,,adCmdText

'

If objRS.EOF Then

    '

    Response.Write("No Records Match")

    '

Else

    '

    pvariable = objRS("LastTrade")

    '

End If

'

objRS.close

Set objRS = Nothing



Second thing - make sure your clean up your ADO objects, before you

Response.Redirect. if you .Open something, then you .Close it. If you Set

something, you Set = Nothing. You need to do this especially for connection

objects.



Thirdly, you should probably look at having a better naming scheme for your

variables. Names like "Date" aren't useful, since what it is the date of? A

start date? End date? ExpiryDate? OrderDate? etc etc



Likewise, pvariable doesn't tell anyone what it is. How about

strLastTradeTime?



Cheers

Ken





~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

----- Original Message -----

From: <lodris@m...>

To: "ASP Databases" <asp_databases@p...>

Sent: Monday, May 28, 2001 8:13 PM

Subject: [asp_databases] update and select problem





: Cant seem to get this working its telling me theres an error on line 60---

: pvariable = rs("LastTrade")

: but i have this exact same line on another page and it works fine .The

: error its giving me is this

: ADODB.Field error '800a0bcd'

:

: Either BOF or EOF is True, or the current record has been deleted; the

: operation requested by the application requires a current record.

:

: /lodris-ca4/sellget.asp, line 60

: but i know that that field is populated cause i checked it

: does anyone know whats wrong?

: Thanks

: Leigh

:

:

:

: <%

:   dim share,qleigh

:  share = Request.QueryString("ShareOption")

: qleigh = Request.QueryString("quantity")

:

:

:

:

:

:   dim rst, conn, strSQL,rs6,rs1 ,rs2 ,rs3 ,rs4 ,rs5, pvariable,

: balvarialbe, newbal, costsofstock, qvariable

:   set conn = Server.CreateObject("ADODB.Connection")

: conn.Open  "DSN=project; uid=lodris-ca4; pwd=lodris1141;"

: set rst=server.CreateObject("ADODB.Recordset")

: set rst = conn.execute  ("Select ShareOption, Quantity, Price,

: Date_bought, balance,sell_date,saleprice FROM sharesuser WHERE UserName

: = '" & Session("strLogin") & "' ")

:

: set rs = conn.execute("select LastTrade from trade where StockName = '" &

: share & "' AND (getday =  '"& Date &  "') ")

: pvariable = rs ("LastTrade")

:

:

: set rs1 = conn.execute("select balance from sharesuser where UserName = '"

: & Session("strLogin") & "' ")

: balvarialbe = rs1("balance")

:

: set rs5= conn.execute("select Quantity from sharesuser where ShareOption

: = '" & share & "'  ")

: qvariable = rs5 ("Quantity")

:

: costsofstock = (qleigh * pvariable )

: updatebal = (balvarialbe + pvariable )

: newquant =( qvariable - qleigh )

:

: 'Response.Write "balvarialbe="&(balvarialbe)&"<br>"

: 'Response.Write "sharecost="&(sharecost)&"<br>"

: strSQL = ("UPDATE sharesuser SET balance = " & updatebal & " where

: UserName = '" & Session("strLogin") & "' ")

: strSQL1=("UPDATE sharesuser SET  quantity = " & newquant & " where

: UserName = '" & Session("strLogin") & "' ")

: strSQL2 = ("INSERT INTO sharesuser (sell_date ,saleprice ) VALUES ( '" &

: now() & "' ," & pvariable & " )")

: 'Response.Write "strSQL ="&(strSQL)&"<br>"

: msg="Less then or equal to 0"

: msg2="True"

: msg3="cant sell"

: if cdbl(qleigh) <= 0 then

: Response.Write (msg)

: response.redirect "leigh7.html"

: elseif cdbl(qvariable) >= cdbl(qleigh) then

: Response.Write (msg2)

: set rs2=conn.execute(strSQL)

: set rs3=conn.execute(strSQL1)

: set rs4=conn.execute(strSQL2)

: else

: Response.Write (msg3)

: response.redirect "leigh7.html"

: end if






  Return to Index