Jump to content
Sign in to follow this  

Update in ADODB

Recommended Posts


I am using a proprietary database ( c-tree ) with an odbc driver written by Faircom.

I can use a free program ( Passport/ODBCTableview) to view table and even edit fields ( or add new records if needed. ) I use the the System ODBC entry created from the Faircom drivers.

Using those same drivers in Autoit, I can read any table/fields I want, but the .update command fails. I have tried with parenthesese and without. Strangely, the .updatecancel does not return an error.

Oh, and the supports() method returns true for the AdUpdate constant. Any ideas?

; Cursor Type
const $adOpenForward = 0
const $adOpenKeyset = 1
const $adOpenDynamic = 2
const $adOpenStatic = 3
; Cursor Location
const $adUseNone = 0
const $adUseServer = 1
const $adUseClient = 2
const $adUseClientBatch = 3
; Lock
const $adLockReadOnly = 0
const $adLockPessimistic = 1
const $adLockOptimistic = 2
const $adLockBatchOptimistic = 3
; Supports
const $adHoldRecords = 0x00000100
 const $adMovePrevious = 0x00000200
const  $adAddNew = 0x01000400
const  $adDelete = 0x01000800
const  $adUpdate = 0x01008000
const  $adBookmark = 0x00002000
const  $adApproxPosition = 0x00004000
const  $adUpdateBatch = 0x00010000
const  $adResync = 0x00020000
const  $adNotify = 0x00040000

$conn = ObjCreate( "ADODB.Connection" )
$DSN = "Spillman;"
$rs = ObjCreate( "ADODB.RecordSet" )
$rs.activeconnection = $conn
$rs.cursortype = $adOpenStatic
$rs.locktype = $adLockOptimistic

$number = "   C45476"
$rs.Open( "SELECT * from nmmain where ""nmmain"".""number"" = '" & $number & "' ")


$fl = "middle"

if $rs.eof then
    msgbox(0,"NOT","Not Found")
    MsgBox(0, "AutoIT-SQL Result", $rs.fields($fl).name & "   = " & $rs.Fields($fl ).Value )
    $rs.fields($fl).value = "STEPHEN2"


func Message($d)

ERROR Returned is

>Running:(\Program Files\AutoIt3\autoit3.exe "NameTest.au3"    
NameTest.au3 (49) : ==> The requested action with this object has failed.:
$rs.Update^ ERROR
->10:40:16 AutoIT3.exe ended.rc:

Any ideas?

Share this post

Link to post
Share on other sites

Add COM Error handler to see the detailed error description.

Example how to do it is in Autoit's helpfile.

EDIT: Also

instead of

$rs = ObjCreate( "ADODB.RecordSet" )

$rs.activeconnection = $conn

$rs.cursortype = $adOpenStatic

$rs.locktype = $adLockOptimistic

$number = "   C45476"

$rs.Open( "SELECT * from nmmain where ""nmmain"".""number"" = '" & $number & "' ")


$rs = ObjCreate( "ADODB.RecordSet" )

$rs.cursortype = $adOpenStatic

$rs.locktype = $adLockOptimistic

$number = "   C45476"

$rs.Open( "SELECT * from nmmain where ""nmmain"".""number"" = '" & $number & "' ", $conn)

Edited by Zedna

Share this post

Link to post
Share on other sites

In addition to what Zedna suggested (in particular the COM error handler), you could try update (or delete) from a separate UPDATE query.

Of course, only try this on a work copy, not on the production version!

Something along the line:

$rs = ObjCreate( "ADODB.RecordSet" )
$rs.activeconnection = $conn
$rs.cursortype = $adOpenStatic
$rs.locktype = $adLockOptimistic

$number = " C45476"
$rs.Open( "update nmmain set nmmain.number = ' Z99999' where nmmain.number = '" & $number & "';")

gives ?

Edited by jchd

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.