how to use array to update recordset of ado?

Results 1 to 2 of 2

Thread: how to use array to update recordset of ado?

  1. #1
    Join Date
    Dec 1969

    Default how to use array to update recordset of ado?

    hi,<BR><BR>does anyone know how to update the recordset of ADO by using array in ASP?<BR><BR>for example, the source code below:<BR><BR>&#060;%<BR> Set Conn = Server.CreateObject("ADODB.Connection")<BR> Conn.Open "ADOExcel"<BR><BR> Set objRS = Server.CreateObject("ADODB.Recordset")<BR> objRS.ActiveConnection = Conn<BR> objRS.CursorType = 3<BR> objRS.LockType = 2<BR> objRS.Source = "Select * From personnel" <BR> &#039;personnel is the name = of the table in the excel file<BR> objRS.Open=20<BR><BR> Dim myArray(5)<BR> myArray(0) = "a"<BR> myArray(1) = "b"<BR> myArray(2) = "c"<BR> myArray(3) = "d"<BR> myArray(4) = "e"<BR> Dim i<BR> i=0<BR><BR> objRS.MoveFirst<BR> do while not objRS.eof<BR> objRS.Fields(0).Value = myArray(i)<BR> &#039;if I put a definite value say = myArray(0) or "a" here it can work well. but when myArray(i), it fails.<BR> objRS.Fields(1).Value = "g"<BR> objRS.Fields(2).Value = "28"<BR> objRS.movenext<BR>&#039;error report here. Type d&#039;erreur :<BR>&#039;Microsoft OLE DB Provider for ODBC Drivers (0x80004005)<BR>&#039;Query-based update failed because the row to update could not be found.<BR> i=i+1<BR> Loop<BR><BR> objRS.close<BR> set objRS=3Dnothing<BR> conn.close<BR> set conn=3Dnothing<BR>%&#062;<BR><BR>aprreciated for any help offered.<BR><BR>Pierre huang

  2. #2
    Join Date
    Dec 1969

    Default Doesn't make sense to me

    ...if using MyArray(0) works, why wouldn&#039;t MyArray(i) when i is zero?<BR><BR>But try this:<BR><BR>&#060;%<BR>...<BR>do while not objRS.eof<BR> [hl="yellow"]temp = myArray(i)[/hl]<BR> objRS.Fields(0).Value = [hl="yellow"]temp[/hl]<BR> objRS.Fields(1).Value = "g"<BR> objRS.Fields(2).Value = "28"<BR> [hl="yellow"]objRS.Update[/hl] &#039; you missed this VERY important step!<BR> objRS.movenext<BR> i = i + 1<BR> [hl="yellow"]If i &#062; UBound( myArray) Then Exit Do[/hl] &#039; just in case!<BR>Loop<BR>...<BR>%&#062;<BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts