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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Update multiple records in Database

Status
Not open for further replies.

2122002

IS-IT--Management
Apr 22, 2003
58
US
Dear All,

I have been surffering to update multiple records in a table/database. Below is my code, when executed, I got the message "Record Save" however, if I check my table "PaySelection" record never updates. Please help, I new to ASP codes.

==============================================

Dim rsPay , Pcode, Sessn, PersonID, gradeslevel

Pcode=Request.Form("PayCode")
grades = Request.Form("gradeslevel")
PersonID= Request.Form("PersonID")

Sessn = request.Form("Sessn")


if trim(gradeslevel) = "" or trim(gradeslevel) = "," then
response.Write "Select the grade level you want to updated" : response.End
end if

set myConn=Server.CreateObject("ADODB.Connection")
set rsPay = Server.CreateObject("ADODB.Recordset")
myConn.Open "Payroll"

'//'// get the individual payrollID
Dim NewID ,icnt
dim Newgrade, gcnt
NewID = split(PersonID,",")

For icnt = 0 To UBound(NewID) - 1
'Response.write NewID(icnt) : response.End

'// get the individual grades levels
Newgrade = split(gradeslevel,",")

For gcnt = 0+gcnt to Ubound(Newgrade) - 1

SQL = "UPDATE PaySelection SET GradesLevel = '"& Newgrade(gcnt) &"' WHERE PayCode = '"&Pcode&"' AND Session = '"&Sessn&"' AND PersonID = '"& NewID(icnt) &"' "

'response.Write sql : response.End

myConn.Execute sql
'response.write sql
gcnt = gcnt + 1

Exit for

Next
SQL = "UPDATE PaySelection SET GradesLevel = '"& Newgrade(gcnt) &"' WHERE PayCode = '"&Pcode&"' AND Session = '"&Sessn&"' AND PersonID = '"& NewID(icnt) &"' "

'response.Write sql : response.End

myConn.Execute sql
'response.write sql

Next


set rsPay = Nothing
set myConn = nothing

%>
<p align="center"><b><font face="Tahoma" color="#0000FF" size="2">Record Successfully updated !</font></b></p>
<p>&nbsp;</p>
<p align="center">
<input type="button" value=" &lt;&lt; Back " onClick="javascript:window.navigate('cngpayroll.asp')">
</body>
</p>

</html>


Dan
 
Anytime you process the page, it will always return the "Record Successfully updated" message because it is not being validated in any manner (it is not checking to see whether the update was successful before running the code). You could enter some validation code to check that before you print it if you wanted to.

More importantly, you may want to do some response.write statements where you are creating your SQL statements to print those out for testing to make sure that your statements are correct. It looks like you have rem'd those statements out at the moment, but did you test to make sure that they were correct (by testing them in your database)? I'd start there and if you have further questions/issues, post back.

------------------------------------------------------------------------------------------------------------------------
"Men occasionally stumble over the truth, but most of them pick themselves up and hurry off as if nothing ever happened."
- Winston Churchill
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top