ASP - Update multiple records in asp

Asked By Anthony t on 21-Jul-05 02:08 PM
Hi 
I am learning asp and I would like to know how to 
update multiple records at the same time. 
I currently have a page that I created that displays my stock portfolio 
I would like to update the price quotes and then click a submit button and have all the 
prices update. 
Thanks

Use BatchUpdate of recordset

Asked By Aarthi Saravanakumar on 21-Jul-05 02:21 PM
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ado270/htm/mdmthupdatebatch.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ado270/htm/mdobjodbrec.asp

How to incorporate batchupdate

Asked By Anthony t on 21-Jul-05 02:34 PM
Hi 
Thanks for responding 
I read the first link about updatebatch 
but I am not sure how I would incorporate it into asp code. 
Can you give me a link that already demonstrates how to write an asp page where I could update multiple records at the same time.
Thank You

ASP batch Update

Asked By Aarthi Saravanakumar on 21-Jul-05 02:53 PM
Here are Some:
http://www.4guysfromrolla.com/webtech/100199-2.shtml
though this is not really a batch update, it loops through records one after the other and really makes it "LOOK" like a batch updates.
This is a VB example for Batch update
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ado270/htm/mdmthupdatebatchx.asp
To change this to work in ASP, all that you need to is late binding.
replace Dim obj as New ADODB.Connection
etc by 
Dim obj
obj=Server.CreateObject("ADODB.Connection")
Not able to add code
Asked By Anthony t on 21-Jul-05 03:31 PM
Hi
I tried to add the code to what I already have but it didn't seem to work.
I understood some of the code but not all of it. 
I am attaching my original code so that it can be converted. 
-- first page -- edit.asp
<html>
 <head>
  <title>My Stocks</title>
 </head>
<body>
   <table width=100% height=36  border=0 cellpadding=0 cellspacing=0 bgcolor=#E5EEF9>
      <tr>
        <th scope=col><table width=100% height=26  border=0 cellpadding=0 cellspacing=0 bgcolor=#B4CCEB>
          <tr>
            <th scope=col align = right ><a href = "index.asp">Home</a> | <a href = "add.html">Add</a> | <a href = "delete.asp">Delete</a> | <a href = "edit.asp">Edit</a></th>
          </tr>
        </table></th>
      </tr>
    </table> 
 <table font width = 100% border = 0 cellspacing = 0 cellpadding = 0>
  <tr>
   <th width = 15%></th>
   <th width = 10%>Name</th>
   <th width = 10%>Symbol</th>
   <th width = 10%>Pur Date</th>
   <th width = 10%>Trade Date</th>
   <th width = 10%>Shares</th>
   <th width = 10%>Cost</th>
   <th width = 10%>Value</th>
   <th width = 15%></th>
  </tr>
 </table>
 <table align = center bgcolor = #B4CCEB width = 70%><tr><th></th></tr></table>
 <form action = "edit_records.asp" name = "form" medthod = "post"  >
 <%
  Dim adoCon
  Dim rs 
  Dim strSQL
  set adoCon = Server.CreateObject("ADODB.Connection")
  adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("stocks.mdb")
  Set rs = Server.CreateObject("ADODB.Recordset")
  strSQL = "SELECT * FROM stocks;"
  rs.Open strSQL, adoCon
Do While not rs.EOF
  'Write the HTML to display the current record in the recordset
  Response.Write("<table width = '100%' border = '0' cellspacing = '0' cellpadding = '0'>")
  Response.Write("<tr>")
  Response.Write("<th width = '15%'><input type = text name = txtid value ='" & rs("txtid") &"' size = '10'></th>")
  Response.Write("<th width = '10%'><input type = text name = txtcompanyname value ='" & rs("txtcompanyname") &"' size = '10'></th>")
  Response.Write("<th width = '10%'><input type = text name = txtsymbol value ='" & rs("txtsymbol") &"' size = '10'></th>")
  Response.Write("<th width = '10%'><input type = text name = txtpurdate value ='" & rs("txtpurdate") &"' size = '10'></th>")
  Response.Write("<th width = '10%'><input type = text name = txttradedate value ='" & rs("txttradedate") &"' size = '10'></th>")
  Response.Write("<th width = '10%'><input type = text name = txtshares value ='" & rs("txtshares") &"' size = '10'></th>")
  Response.Write("<th width = '10%'><input type = text name = txtcost value ='" & rs("txtcost") &"' size = '10'></th>")
  Response.Write("<th width = '10%'><input type = text name = txtvalue value ='" & rs("txtvalue") &"' size = '10'></th>")
  Response.Write("<th width = '15%'></th>")
  Response.Write("</tr>")
  Response.Write("</table>")
  rs.MoveNext
Loop	
rs.Close
Set rs = Nothing
Set adoCon = Nothing
%>
 <table width = "100%" align = right><tr><th><input type = submit value = "update"></th></tr></table>
<br><br>
 </form>
</body>
</html>
-- send page -- edit_records.asp
<% 'Dimension variables
Dim adoCon            'Holds the Database Connection Object 
Dim rsUpdateEntry   'Holds the recordset for the record to be updated
Dim strSQL             'Holds the SQL query to query the database 
Dim lngRecordNo      'Holds the record number to be updated
txtid=Request.Form("txtid")
txtcompanyname=Request.Form("txtcompanyname")
txtsymbol=Request.Form("txtsymbol")
txtpurdate=Request.Form("txtpurdate")
txttradedate=Request.Form("txttradedate")
txtshares=Request.Form("txtshares")
txtcost=Request.Form("txtcost")
txtvalue=Request.Form("txtvalue")
'Create an ADO connection object
Set adoCon = Server.CreateObject("ADODB.Connection")
'Set an active connection to the Connection object using a DSN-less connection
adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("stocks.mdb")
'Create an ADO recordset object
Set rsUpdateEntry = Server.CreateObject("ADODB.Recordset")
'Initialise the strSQL variable with an SQL statement to query the database
strSQL = "SELECT stocks.* FROM stocks WHERE txtid=" & lngRecordNo
'Set the cursor type we are using so we can navigate through the recordset
rsUpdateEntry.CursorType = 2
'Set the lock type so that the record is locked by ADO when it is updated
rsUpdateEntry.LockType = 3
'Update the record in the recordset
rsUpdateEntry.Fields("txtcompanyname") = Request.Form("txtcompanyname")
rsUpdateEntry.Fields("txtsymbol") = Request.Form("txtsymbol")
rsUpdateEntry.Fields("txtpurdate") = Request.Form("txtpurdate")
rsUpdateEntry.Fields("txttradedate") = Request.Form("txttradedate")
rsUpdateEntry.Fields("txtshares") = Request.Form("txtshares")
rsUpdateEntry.Fields("txtcost") = Request.Form("txtcost")
rsUpdateEntry.Fields("txtvalue") = Request.Form("txtvalue")
'Write the updated recordset to the database
rsUpdateEntry.Update
'Reset server objects
rsUpdateEntry.Close
Set rsUpdateEntry = Nothing
Set adoCon = Nothing
Response.ReDirect "index.asp"
%>
Found another piece of code on the web
Asked By Anthony t on 21-Jul-05 04:09 PM
Hi 
I found a piece of code on the internet that seems to do what I want but I am not sure how to configure it so that it will allow me to edit the following 
database: stocks
fields: txtcompanyname,txtsymbol,txtpurdate,txttradedate,txtshares,txtcost,txtvalue
I found this code at:http://www.drdev.net/article11.asp
here is the code it is only one page 
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<%
If Request("Submit") <> "" Then
	intRecIDs = Replace(Request("hidRecIDs"), "*", "")  ' remove all the asterisks, to create a list like this: 2, 5, 8, 9 etc.
	arrRecIDs = Split(intRecIDs, ", ")				' Create an array, wich will contain just the IDs of the records we need to update
	For i = 0 to Ubound(arrRecIDs)					' Loop trough the array
		strText = Replace(Request("txtText" & arrRecIDs(i)), "'", "''")
		intNum  = Replace(Request("txtNum" & arrRecIDs(i)), "'", "''")
		set commUpdate = Server.CreateObject("ADODB.Command")
		commUpdate.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("TestDB.mdb") & ";Persist Security Info=False"
		commUpdate.CommandText = "UPDATE TestTable  SET RecText = '" & strText & "', RecNum = " & intNum & " WHERE RecID = " & arrRecIDs(i)
		commUpdate.CommandType = 1
		commUpdate.CommandTimeout = 0
		commUpdate.Prepared = true
		commUpdate.Execute()
	Next
	strMessage = i & " Records Updated"
	Response.Redirect("MultiUpdateDemo.asp?Message=" & strMessage)
End If
%>
<%
Dim Recordset1
Dim Recordset1_numRows
Set Recordset1 = Server.CreateObject("ADODB.Recordset")
Recordset1.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("TestDB.mdb") & ";Persist Security Info=False"
Recordset1.Source = "SELECT RecID, RecText, RecNum  FROM TestTable"
Recordset1.CursorType = 0
Recordset1.CursorLocation = 2
Recordset1.LockType = 1
Recordset1.Open()
Recordset1_numRows = 0
%>
<%
Dim Repeat1__numRows
Dim Repeat1__index
Repeat1__numRows = -1
Repeat1__index = 0
Recordset1_numRows = Recordset1_numRows + Repeat1__numRows
%>
<html>
<head>
<title>Update Demo</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript">
<!--
//  When the value in a textfield is changed, notice the onChange="RecUpdate('<%= intRecID %>')"
//  on each of the textfields,  the value of the Record ID associated with that field
//  is passed to the RecUpdate function. First the value is surounded with 2 asterisks e.g. *6*
//  This is so that *1* can be distinguished from *10*, *11* etc.
function RecUpdate(RecID){
var ThisID = "*" + (RecID) + "*"
if (document.form1.hidRecIDs.value == ""){	// If the hidden field is empty
document.form1.hidRecIDs.value = (ThisID)	// Store the value in the hidden field (hidRecIDs) as it is.
}
if (document.form1.hidRecIDs.value != ""){  // If the hidden field isn't empty
var str = document.form1.hidRecIDs.value;	// Store the contents of the hidden field in the variable str
var pos = str.indexOf(ThisID);				// Search str to see if this RecID is allready in it.
if (pos == -1) {							// If the position returned is -1 it isn't allredy in there,  
document.form1.hidRecIDs.value = document.form1.hidRecIDs.value + ", " + (ThisID)  
} 											// so add ", " and this ID to what is already in hidRecIDs 
}											// to create a list like this *2*, *5*, *8* etc.	
}
//-->
</script>
</head>
<body>
<font size="2" face="Arial, Helvetica, sans-serif"><%= Request.QueryString("Message") %></font>
 <br>
<form name="form1" method="post" action="MultiUpdateDemo.asp">
<table width="500" border="0" cellpadding="0" cellspacing="1" bgcolor="#666699">
  <tr>
    <td><table width="500" border="0" cellpadding="0" cellspacing="6" bgcolor="#EEEFF2">
      <tr>
        <td width="37"><strong><font color="#333333" size="1" face="Arial, Helvetica, sans-serif">RecID</font></strong></td>
        <td width="217"><strong><font color="#333333" size="1" face="Arial, Helvetica, sans-serif">RecText</font></strong></td>
        <td width="226"><strong><font color="#333333" size="1" face="Arial, Helvetica, sans-serif">RecNum</font></strong></td>
      </tr>
      <% 
While ((Repeat1__numRows <> 0) AND (NOT Recordset1.EOF)) 
%>
<% intRecID =(Recordset1.Fields.Item("RecID").Value) ' Store the current RecordID in a variable %>
      <tr>
        <td nowrap><font size="1" face="Arial, Helvetica, sans-serif"><%= intRecID %><input name="hidRecID<%= intRecID %>" type="hidden" value="<%= intRecID %>" size="5"></font></td>
        <td nowrap><font size="1" face="Arial, Helvetica, sans-serif"><input name="txtText<%= intRecID %>" type="text" onChange="RecUpdate('<%= intRecID %>')" value="<%=(Recordset1.Fields.Item("RecText").Value)%>" size="20"></font></td>
        <td nowrap><font size="1" face="Arial, Helvetica, sans-serif"><input name="txtNum<%= intRecID %>" type="text" onChange="RecUpdate('<%= intRecID %>')" value="<%=(Recordset1.Fields.Item("RecNum").Value)%>" size="20"></font></td>
      </tr>
      <% 
  Repeat1__index=Repeat1__index+1
  Repeat1__numRows=Repeat1__numRows-1
  Recordset1.MoveNext()
Wend
%>
    </table></td>
  </tr>
</table>
<br>
<input name="hidRecIDs" type="text" size="40">
<font size="2" face="Arial, Helvetica, sans-serif"><=== This would be hidden</font><br>
<br>
<font size="2" face="Arial, Helvetica, sans-serif">
<input type="submit" name="Submit" value="Update">
</font>
</form>
</body>
</html>
<%
Recordset1.Close()
Set Recordset1 = Nothing
%>
Think I misunderstood you
Asked By Aarthi Saravanakumar on 21-Jul-05 04:23 PM
By Batch Update, I think you meant updating multiple column values at the same time.
here is how your second page should look.
However some things you need to consider.
You are emitting as many txtids etc in your edit.asp as there sre records in stock. On update..how do you plan to post this data and differenciate them on edit_records.asp?
below code does it for one record.
-- send page -- edit_records.asp 
replace
'Initialise the strSQL variable with an SQL statement to query the database 
strSQL = "SELECT stocks.* FROM stocks WHERE txtid=" & lngRecordNo 
'Set the cursor type we are using so we can navigate through the recordset 
rsUpdateEntry.CursorType = 2 
'Set the lock type so that the record is locked by ADO when it is updated 
rsUpdateEntry.LockType = 3 
'Update the record in the recordset 
rsUpdateEntry.Fields("txtcompanyname") = Request.Form("txtcompanyname") 
rsUpdateEntry.Fields("txtsymbol") = Request.Form("txtsymbol") 
rsUpdateEntry.Fields("txtpurdate") = Request.Form("txtpurdate") 
rsUpdateEntry.Fields("txttradedate") = Request.Form("txttradedate") 
rsUpdateEntry.Fields("txtshares") = Request.Form("txtshares") 
rsUpdateEntry.Fields("txtcost") = Request.Form("txtcost") 
rsUpdateEntry.Fields("txtvalue") = Request.Form("txtvalue") 
'Write the updated recordset to the database 
rsUpdateEntry.Update 
'Reset server objects 
rsUpdateEntry.Close 
Set rsUpdateEntry = Nothing 
Set adoCon = Nothing 
by
'
'*********NEW CODE ***************************'
'Replace column names by what is in your table
strsql="UPDATE stocks SET "
strsql=strsql & "companyname='" & Request.Form("txtcompanyname") & "',"
strsql=strsql & "symbol='" & Request.Form("txtsymbol")  & "',"
'Do for other columns
strsql=strsql & " WHERE ID='" & Request.Form("txtid") 
'Write the updated recordset to the database 
on error resume next
adoCon.Execute srrSql
if err<>0 then
    response.write("No update permissions!")
  else 
    response.write("Record " & Request.Form("txtid")  & " was updated!")
  end if 
'Reset server objects 
adoCon.Close()
Set adoCon = Nothing 
Response.ReDirect "index.asp" 
%>
differentation of rows
Asked By Abhinav gujjar on 22-Jul-05 07:43 AM
anthony this is a common issue in ASP. iwll outline the steps that you need to follow.
1. First of all when you dynamically emit the HTML elements using Respone.write, each of the rows elements need to be differentiated. obviousy we will use the field txtid from the database to make this differentiation.
so your code in the loop will look like below.. i have appended the iCounter to the element names, this will be used to retrieve the information
dim iCounter = 0
Do While not rs.EOF
  'Write the HTML to display the current record in the recordset
  ' and differntiate the elements of each row
  Response.Write("<table width = '100%' border = '0' cellspacing = '0' cellpadding = '0'>")
  Response.Write("<tr>")
  Response.Write("<th width = '15%'><input type = text name = txtid value ='" & rs("txtid") &"' size = '10'></th>")
  Response.Write("<th width = '10%'><input type = text name = txtcompanyname_" & iCounter & "  value ='" & rs("txtcompanyname") &"' size = '10'></th>")
  Response.Write("<th width = '10%'><input type = text name = txtsymbol_" & iCounter & " value ='" & rs("txtsymbol") &"' size = '10'></th>")
  Response.Write("<th width = '10%'><input type = text name = txtpurdate_" & iCounter & " value ='" & rs("txtpurdate") &"' size = '10'></th>")
  Response.Write("<th width = '10%'><input type = text name = txttradedate_" & iCounter & " value ='" & rs("txttradedate") &"' size = '10'></th>")
  Response.Write("<th width = '10%'><input type = text name = txtshares_" & iCounter & " value ='" & rs("txtshares") &"' size = '10'></th>")
  Response.Write("<th width = '10%'><input type = text name = txtcost_" & iCounter & " value ='" & rs("txtcost") &"' size = '10'></th>")
  Response.Write("<th width = '10%'><input type = text name = txtvalue_" & iCounter & " value ='" & rs("txtvalue") &"' size = '10'></th>")
  Response.Write("<th width = '15%'></th>")
  Response.Write("</tr>")
  Response.Write("</table>")
  rs.MoveNext
  iCounter = iCounter + 1
Loop 
2. Next you need to store the total of the rows that you are displaying.
use 
Response.Write("<input type=hidden name=totalNumberOfRows value ='" & iCounter &"' size = '10'>")
after the looping is done.
3. now when the update routine is called it need to first determine the number of rows that need to be updated ( request from totalNumberOfRows) and then loop through updating each of these rows.
Dim iTotalRows  = Request.Form("iTotalRows") 
for ( i = 0 ; i <= iTotalRows; i++)
{
txtid=Request.Form("txtid_" & i)
txtcompanyname=Request.Form("txtcompanyname_" & i)
txtsymbol=Request.Form("txtsymbol_" & i)
txtpurdate=Request.Form("txtpurdate_" & i)
txttradedate=Request.Form("txttradedate_" & i)
txtshares=Request.Form("txtshares_" & i)
txtcost=Request.Form("txtcost_" & i)
txtvalue=Request.Form("txtvalue_" & i)
// build your string to update here.. USE the string Aarthi provided in the post.
//do the update for this row
// move to next row
}
I hope at least the outline of the solution is clear.. message back if you need any clarifications on specifics
Get Page can not be displayed
Asked By Anthony t on 22-Jul-05 10:49 AM
Hi 
Thanks for the help I added the code that you instructed me to do but when I click on the first page (edit.asp) I get page can not be displayed message. I am not sure where the error is.
Below is the updated code with the recommended changes please look over it for me.
Thanks
-- first page --
<html>
 <head>
  <title>My Stocks</title>
 </head>
<body>
   <table width=100% height=36  border=0 cellpadding=0 cellspacing=0 bgcolor=#E5EEF9>
      <tr>
        <th scope=col><table width=100% height=26  border=0 cellpadding=0 cellspacing=0 bgcolor=#B4CCEB>
          <tr>
            <th scope=col align = right ><a href = "index.asp">Home</a> | <a href = "add.html">Add</a> | <a href = "delete.asp">Delete</a> | <a href = "edit.asp">Edit</a></th>
          </tr>
        </table></th>
      </tr>
    </table> 
 <table font width = 100% border = 0 cellspacing = 0 cellpadding = 0>
  <tr>
   <th width = 15%></th>
   <th width = 10%>Name</th>
   <th width = 10%>Symbol</th>
   <th width = 10%>Pur Date</th>
   <th width = 10%>Trade Date</th>
   <th width = 10%>Shares</th>
   <th width = 10%>Cost</th>
   <th width = 10%>Value</th>
   <th width = 15%></th>
  </tr>
 </table>
 <table align = center bgcolor = #B4CCEB width = 70%><tr><th></th></tr></table>
 <form action = "edit_records.asp" name = "form" medthod = "post"  >
 <%
  Dim adoCon
  Dim rs 
  Dim strSQL
  Dim iCounter = 0 
  set adoCon = Server.CreateObject("ADODB.Connection")
  adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("stocks.mdb")
  Set rs = Server.CreateObject("ADODB.Recordset")
  strSQL = "SELECT * FROM stocks;"
  rs.Open strSQL, adoCon
Do While not rs.EOF
  'Write the HTML to display the current record in the recordset
  Response.Write("<table width = '100%' border = '0' cellspacing = '0' cellpadding = '0'>")
  Response.Write("<tr>")
  Response.Write("<th width = '15%'><input type = text name = txtid value ='" & rs("txtid") &"' size = '10'></th>")
  Response.Write("<th width = '10%'><input type = text name = txtcompanyname value ='" & rs("txtcompanyname") &"' size = '10'></th>")
  Response.Write("<th width = '10%'><input type = text name = txtsymbol value ='" & rs("txtsymbol") &"' size = '10'></th>")
  Response.Write("<th width = '10%'><input type = text name = txtpurdate value ='" & rs("txtpurdate") &"' size = '10'></th>")
  Response.Write("<th width = '10%'><input type = text name = txttradedate value ='" & rs("txttradedate") &"' size = '10'></th>")
  Response.Write("<th width = '10%'><input type = text name = txtshares value ='" & rs("txtshares") &"' size = '10'></th>")
  Response.Write("<th width = '10%'><input type = text name = txtcost value ='" & rs("txtcost") &"' size = '10'></th>")
  Response.Write("<th width = '10%'><input type = text name = txtvalue value ='" & rs("txtvalue") &"' size = '10'></th>")
  Response.Write("<th width = '15%'></th>")
  Response.Write("</tr>")
  Response.Write("</table>")
  rs.MoveNext
  iCounter = iCounter + 1 
Loop
Response.Write("<input type=hidden name=totalNumberOfRows value ='" & iCounter &"' size = '10'>")	
rs.Close
Set rs = Nothing
Set adoCon = Nothing
%>
 <table width = "100%" align = right><tr><th><input type = submit value = "update"></th></tr></table>
<br><br>
 </form>
</body>
</html>
-- second page -- 
<% 'Dimension variables
Dim adoCon            'Holds the Database Connection Object 
Dim rsUpdateEntry   'Holds the recordset for the record to be updated
Dim strSQL             'Holds the SQL query to query the database 
Dim lngRecordNo      'Holds the record number to be updated
'Create an ADO connection object
Set adoCon = Server.CreateObject("ADODB.Connection")
'Set an active connection to the Connection object using a DSN-less connection
adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("stocks.mdb")
Dim iTotalRows  = Request.Form("iTotalRows") 
for ( i = 0 ; i <= iTotalRows; i++) 
{ 
txtid=Request.Form("txtid_" & i) 
txtcompanyname=Request.Form("txtcompanyname_" & i) 
txtsymbol=Request.Form("txtsymbol_" & i) 
txtpurdate=Request.Form("txtpurdate_" & i) 
txttradedate=Request.Form("txttradedate_" & i) 
txtshares=Request.Form("txtshares_" & i) 
txtcost=Request.Form("txtcost_" & i) 
txtvalue=Request.Form("txtvalue_" & i) 
'Create an ADO recordset object
Set rsUpdateEntry = Server.CreateObject("ADODB.Recordset")
strsql="UPDATE stocks SET " 
strsql=strsql & "txtcompanyname='" & Request.Form("txtcompanyname") & "'," 
strsql=strsql & "txtsymbol='" & Request.Form("txtsymbol")  & "'," 
strsql=strsql & "txtpurdate='" & Request.Form("txtpurdate")  & "'," 
strsql=strsql & "txttradedate='" & Request.Form("txttradedate")  & "'," 
strsql=strsql & "txtshares='" & Request.Form("txtshares")  & "'," 
strsql=strsql & "txtcost='" & Request.Form("txtcost")  & "'," 
strsql=strsql & "txtvalue='" & Request.Form("txtvalue")  & "'," 
'Do for other columns 
strsql=strsql & " WHERE ID='" & Request.Form("txtid") 
'Write the updated recordset to the database 
on error resume next 
adoCon.Execute srrSql 
if err<>0 then 
    response.write("No update permissions!") 
  else 
    response.write("Record " & Request.Form("txtid")  & " was updated!") 
  end if 
'Reset server objects 
adoCon.Close() 
Set adoCon = Nothing 
Response.ReDirect "index.asp" 
%>
detailed error message
Asked By Abhinav gujjar on 22-Jul-05 10:53 AM
you need to go to internet explorer > tools > advanced > Show Friendly http Error messages. now uncheck this box so that you get a more detailed error message as to what went wrong.
oh and also simply pasting the code i provided will not work.. the code i provided should be used as a template. its there to show you the way as to how it can be done
error message
Asked By Anthony t on 22-Jul-05 10:58 AM
okay this what I received as the error message 
Microsoft VBScript compilation error '800a0401' 
Expected end of statement 
/at51178/mystocks/edit.asp, line 34 
Dim iCounter = 0
-------------^
You can't do that
Asked By Jon Wojtowicz on 22-Jul-05 07:02 PM
in VB script. Change it to
Dim iCounter
iCounter = 0
like i said
Asked By Abhinav gujjar on 23-Jul-05 05:42 AM
dont use my code as it is .. think of it as pseudo code
this statement needs to be split into 
Dim iCounter
iCounter = 0
.. you may find other places with such probs .. i'll try and help as much as i can ..
in fact if you prvoide the files to me .. i can set this up for you
where should I send it to
Asked By Anthony t on 24-Jul-05 10:41 AM
Where should I send the files to
problem with second page
Asked By Anthony t on 25-Jul-05 12:13 AM
hi 
jon thanks for the repsonse
I do have another problem though 
It looks like there is a problem with the for i statement with the second page of the script. I tried to resolve it without any success.
- second page -- 
<% 'Dimension variables 
Dim adoCon            'Holds the Database Connection Object 
Dim rsUpdateEntry   'Holds the recordset for the record to be updated 
Dim strSQL             'Holds the SQL query to query the database 
Dim lngRecordNo      'Holds the record number to be updated 
'Create an ADO connection object 
Set adoCon = Server.CreateObject("ADODB.Connection") 
'Set an active connection to the Connection object using a DSN-less connection 
adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("stocks.mdb") 
Dim iTotalRows  = Request.Form("iTotalRows") 
for ( i = 0 ; i <= iTotalRows; i++) 
{ 
txtid=Request.Form("txtid_" & i) 
txtcompanyname=Request.Form("txtcompanyname_" & i) 
txtsymbol=Request.Form("txtsymbol_" & i) 
txtpurdate=Request.Form("txtpurdate_" & i) 
txttradedate=Request.Form("txttradedate_" & i) 
txtshares=Request.Form("txtshares_" & i) 
txtcost=Request.Form("txtcost_" & i) 
txtvalue=Request.Form("txtvalue_" & i) 
'Create an ADO recordset object 
Set rsUpdateEntry = Server.CreateObject("ADODB.Recordset") 
strsql="UPDATE stocks SET " 
strsql=strsql & "txtcompanyname='" & Request.Form("txtcompanyname") & "'," 
strsql=strsql & "txtsymbol='" & Request.Form("txtsymbol")  & "'," 
strsql=strsql & "txtpurdate='" & Request.Form("txtpurdate")  & "'," 
strsql=strsql & "txttradedate='" & Request.Form("txttradedate")  & "'," 
strsql=strsql & "txtshares='" & Request.Form("txtshares")  & "'," 
strsql=strsql & "txtcost='" & Request.Form("txtcost")  & "'," 
strsql=strsql & "txtvalue='" & Request.Form("txtvalue")  & "'," 
'Do for other columns 
strsql=strsql & " WHERE ID='" & Request.Form("txtid") 
'Write the updated recordset to the database 
on error resume next 
adoCon.Execute srrSql 
if err<>0 then 
    response.write("No update permissions!") 
  else 
    response.write("Record " & Request.Form("txtid")  & " was updated!") 
  end if 
'Reset server objects 
adoCon.Close() 
Set adoCon = Nothing 
Response.ReDirect "index.asp" 
%>
my id
Asked By Abhinav gujjar on 25-Jul-05 12:50 AM
send them across at abhinavgujjar@gmail.com.
i dont know how this fits in with the forums policy.. anyway. just send them across
First thing
Asked By Jon Wojtowicz on 25-Jul-05 05:48 AM
Dim iTotalRows  = Request.Form("iTotalRows")
needs to be on two separate lines
Dim iTotalRows
iTotalRows  = Request.Form("iTotalRows")
I'm not sure what is happening in this block of code
txtid=Request.Form("txtid_" & i)
txtcompanyname=Request.Form("txtcompanyname_" & i)
txtsymbol=Request.Form("txtsymbol_" & i)
txtpurdate=Request.Form("txtpurdate_" & i)
txttradedate=Request.Form("txttradedate_" & i)
txtshares=Request.Form("txtshares_" & i)
txtcost=Request.Form("txtcost_" & i)
txtvalue=Request.Form("txtvalue_" & i)
'Create an ADO recordset object
Set rsUpdateEntry = Server.CreateObject("ADODB.Recordset")
strsql="UPDATE stocks SET "
strsql=strsql & "txtcompanyname='" & Request.Form("txtcompanyname") & "',"
strsql=strsql & "txtsymbol='" & Request.Form("txtsymbol")  & "',"
strsql=strsql & "txtpurdate='" & Request.Form("txtpurdate")  & "',"
strsql=strsql & "txttradedate='" & Request.Form("txttradedate")  & "',"
strsql=strsql & "txtshares='" & Request.Form("txtshares")  & "',"
strsql=strsql & "txtcost='" & Request.Form("txtcost")  & "',"
strsql=strsql & "txtvalue='" & Request.Form("txtvalue")  & "',"
'Do for other columns
strsql=strsql & " WHERE ID='" & Request.Form("txtid")
It appears you are setting assigning form variables to local variables but are not using them. The pattern of those variables looks different than the ones in you sql statement. Is this the correct pattern you need? Should you be referring to the variable names inside your sql statement rather than accessing form variables?
update to the second page
Asked By Anthony t on 25-Jul-05 02:19 PM
Hi 
Okay I configured my second page of the script and I am to click the button on the first page and take me to the second page but the second page is not updating the the fields.
--second page --
<% 'Dimension variables
Dim adoCon            'Holds the Database Connection Object 
Dim rsUpdateEntry   'Holds the recordset for the record to be updated
Dim strSQL             'Holds the SQL query to query the database 
Dim lngRecordNo      'Holds the record number to be updated
'Create an ADO connection object
Set adoCon = Server.CreateObject("ADODB.Connection")
'Set an active connection to the Connection object using a DSN-less connection
adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("stocks.mdb")
Dim iTotalRows  
Dim i
for i = 1 to Request.Form("iTotalRows").Count
txtid=Request.Form("txtid_" & i) 
txtcompanyname=Request.Form("txtcompanyname_" & i) 
txtsymbol=Request.Form("txtsymbol_" & i) 
txtpurdate=Request.Form("txtpurdate_" & i) 
txttradedate=Request.Form("txttradedate_" & i) 
txtshares=Request.Form("txtshares_" & i) 
txtcost=Request.Form("txtcost_" & i) 
txtvalue=Request.Form("txtvalue_" & i) 
'Create an ADO recordset object
Set rsUpdateEntry = Server.CreateObject("ADODB.Recordset")
strsql="UPDATE stocks SET " 
strsql=strsql & "txtcompanyname='" & Request.Form("txtcompanyname") & "'," 
strsql=strsql & "txtsymbol='" & Request.Form("txtsymbol")  & "'," 
strsql=strsql & "txtpurdate='" & Request.Form("txtpurdate")  & "'," 
strsql=strsql & "txttradedate='" & Request.Form("txttradedate")  & "'," 
strsql=strsql & "txtshares='" & Request.Form("txtshares")  & "'," 
strsql=strsql & "txtcost='" & Request.Form("txtcost")  & "'," 
strsql=strsql & "txtvalue='" & Request.Form("txtvalue")  & "'," 
'Do for other columns 
strsql=strsql & " WHERE ID='" & Request.Form("txtid") 
next
'Write the updated recordset to the database 
on error resume next 
adoCon.Execute srrSql 
if err<>0 then 
    response.write("No update permissions!") 
  else 
    response.write("Record " & Request.Form("txtid")  & " was updated!") 
  end if 
'Reset server objects 
adoCon.Close() 
Set adoCon = Nothing 
Response.ReDirect "index.asp" 
%>