Results 1 to 2 of 2

Thread: Edit data in DB, ADO

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2005
    Posts
    13

    Edit data in DB, ADO

    Hi

    Wich ADO command should I use to edit data in a DB. If the value to be entered in the primary key column already exists data should be fetched, to view, and updated. Which command should I use to uppdate? I could use commanddb and a SQLstring. But I would rather pass an array, as in the addnew command.

    kaaja

  2. #2
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Re: Edit data in DB, ADO

    Sounds like a recordset object, with an sql statement.
    If it returns (.eof is false) then edit the record, update via the screen. Otherwise .EOF is true and you have no records. So use .addnew and do the same update part as in the edit.

    Example code (one way)
    Code:
    strsql = "Sql statement to open"
    rst.open strsql,currentproject.connection,2,3,1 (dynamic, optimistic, adcmdtext)
    
    if rst.eof then
      rst.addnew
      rst("fieldnameID") = number to be added
    endif
    
    rst("otherfields") = txtfields
    rst("otherfields") = txtfields
    rst("otherfields") = txtfields
    
    rst.update
    rst.close
    You need to add in error checking etc..

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

Posting Permissions

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



Click Here to Expand Forum to Full Width