Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Batch Update

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2001-07-18 : 08:26:02
Scott Iwamoto writes "I am setting up my site using an article from the 4GuysFrom Rolla site ("Using Forms to Do Batch Updates").

I changed the ListProducts.asp page to reflect my database and now I am working on setting up the UpdateCosts.asp page.

The question I have is that in the example only COST is being updated. How do I update multiple items? I set up the variables but do not understand how to insert them correctly into the strSQL variable.

Code Follows:

set objRS = Server.CreateObject("ADODB.Recordset")
objRS.ActiveConnection = MM_connTravelweb_STRING
objRS.Source = "SELECT Reportid, from_date, to_date, category, days, funding, cost FROM Absence"
objRS.CursorType = 0
objRS.CursorLocation = 2
objRS.LockType = 3
objRS.Open()
objRS_numRows = 0

Option Explicit

Response.Buffer = True

'First, we need to get the total number of items that could be updated
Dim iCount
iCount = Request("Count")

'We need to obtain each cost and ID
Dim strFromdate, strTodate, strCategory, strDays, strFunding, strCost, strID

'We will also need to build a SQL statement
Dim strSQL


'Now, we want to loop through each form element
Dim iLoop
For iLoop = 0 to iCount
strFromdate = Request(iLoop & ".from_date")
strTodate = Request(iLoop & ".to_date")
strCategory = Request(iLoop & ".category")
strDays = Request(iLoop & ".days")
strFunding = Request(iLoop & ".funding")
strCost = Request(iLoop & ".Cost")
strID = Request(iLoop & ".ID")

strSQL = "UPDATE Absence SET Cost = " & CDBl(strCost) & _
" WHERE ProductID = " & strID

objRS.Execute strSQL
Next



Response.Redirect "ListProducts.asp"


objRS.Close()

"
   

- Advertisement -