Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to update memo using adchunk and ADO/ODBC?
Message
De
16/03/2005 07:21:53
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Problèmes
Divers
Thread ID:
00996096
Message ID:
00996240
Vues:
21
>>>I need to update a memo field using ADO from as ASP application. I've looked at KB Q208208. It only shows how to add a new record and populate the memo using the "adchunk" approach. I need to know how use this to update a memo in an existing record. I have a free table with a CDX file that has 3 indices. I need to know how to fetch a single record's memo using a unique key value (like using "set order to" then doing a seek in VFP), and then write back an updated version of them memo, all with ADO. I know the syntax for creating a connection, etc, but I don't know the rules/techniques for performing these simple steps. Can somebody help me? Thanks very much!
>>>
>>>Here's what I'm getting: Microsoft OLE DB Provider for ODBC Drivers (0x80004005)
>>>[Microsoft][ODBC Visual FoxPro Driver]Cannot update the cursor.
>>>
>>>Here's the code snippet, given the memo field "comments"
>>>
>>>* This is already done successfully:
>>>Select Comments  From MyDBF Where ID=SomeUniqueKeyVal
>>>* ID is a field that is indexed alone in a rushmore-optimized index
>>>* Assume the connection is named "conn" and the recordset is named "rs"
>>>* Set up the test:
>>>cLongParm=rs("comments") + chr(13) + string(254,"A")
>>>liChunkSize = 254
>>>Rs.Fields("comments")=""
>>>FOR i = 1 to len(lcLongParm) step liChunkSize
>>>  liStartAt = i
>>>  liWorkString = mid(lcLongParm, liStartAt, liChunkSize)
>>>  Rs.Fields("comments").AppendChunk(liWorkString)
>>>NEXT
>>>conn.execute "Set Reprocess to 5 seconds",,1
>>>* This fails:
>>>Rs.Update
>>>
>>
>>It's saying "Cannot update the cursor". W/o memo can it? It sounds more like a security problem.
>>Cetin
>
>Using an UPDATE sql statement passed through ADO works OK, but everything has to be literal (no parameters), and you can't use memo data of more than 254 chars with it. I think you have to use ADO. I've found that if I set RS locking to LockOptimistic and cursortype to openstatic, then RS.Update won't fail with an error but it also won't update anything. I have _really_ searched the web for a solution to this and I'm beginning to wonder if there is one. With a free table, there's no Primary Key defined, and with no PK, I'm wondering if the Update method is supported at all by the VFP ODBC driver through ADO.

Of course there is a solution and instead of web you might do a search on UT. I'm sure I've posted samples before. Anyway here is one that I just tested and worked (ASP - it's a free table and no primary key. I found to locate just by Last_name as for this sample it was the only record with that last_name):
<%
    cSQLSelect = "select * from myFreeEmployee"
    dbpath = Server.MapPath("data")
    set oConnection = Server.CreateObject( "adodb.connection" ) 
    set oRecordSet  = Server.CreateObject( "adodb.RecordSet" )

    with oConnection
       .ConnectionString = "Provider=VFPOLEDB;data source=" & dbpath & "\"
       .Open
    end with
    with oRecordSet
      .CursorType = 2
      .CursorLocation = 3
      .LockType   = 4
      .ActiveConnection = oConnection
      .Source = cSQLSelect
      .Open
      .Find "Last_name like 'Basoz%'"
      .Fields("Notes").Value = "123456789 123456789 123456789 123456789 123456789 " & _
             "123456789 123456789 123456789 123456789 123456789 " & _
             "123456789 123456789 123456789 123456789 123456789 " & _
             "123456789 123456789 123456789 123456789 123456789 " & _
             "123456789 123456789 123456789 123456789 123456789 " & _
             "123456789 123456789 123456789 123456789 123456789 " & _
             "123456789 123456789 123456789 123456789 123456789 " & _
             "123456789 123456789 123456789 123456789 123456789 " & _
             "123456789 123456789 123456789 123456789 123456789 " & _
             "123456789 123456789 123456789 123456789 123456789 " & _
             "123456789 123456789 123456789 123456789 123456789 " & _
             "123456789 123456789 123456789 123456789 123456789 " & _
             "123456789 123456789 123456789 123456789 123456789 " & _
             "123456789 123456789 123456789 123456789 123456789 "
      .UpdateBatch
      .Close
    end with

    set oRs = oConnection.Execute("select First_Name,Last_Name,Notes from myFreeEmployee")
     ' Check results
    Response.Write("<TABLE border='1'><TR><TH>First Name</TH>" & _
    "<TH>Last Name</TH><TH>Notes</TH></TR>" )
    while not oRS.eof
            Response.Write("<TR>")
            Response.Write("<TD>" & oRs.Fields(0).value & "</TD>")
            Response.Write("<TD>" & oRs.Fields(1).value & "</TD>")
            Response.Write("<TD>" & oRs.Fields(2).value & "</TD>")
            Response.Write("</TR>")
            oRs.MoveNext
    wend
    Response.Write("</TABLE><BR/>")

    oConnection.Close
    set oConnection = nothing
%>
PS: I'm sure I also made this work w/o AppendChunk with larger amounts of data read from a file. ie: Something like this:

Set f = fs.OpenTextFile("c:\temp\sometext.txt", 1, 0)
myMemo = f.ReadAll
f.Close
...
oRS.Fields("Notes").Value = myMemo

But I've to admit that my VB knowledge is at zero level. Part of code might be more optimized by a VB coder.
But don't forget security settings. It's iusr_machinename trying to write to file.
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform