ADO update() error

ADO update() error

Postby wzaf » Sat Jun 05, 2010 3:17 pm

Hi All .

I use use ADO to access MySql DB. I try modify a row using :
Code: Select all  Expand view
 

oRecordSet := TOleAuto():New( "ADODB.Recordset" )
oRecordSet:CursorType := adOpenDynamic
oRecordSet:CursorLocation := adUseClient
oRecordSet:LockType := adLockOptimistic

TRY
oRecordSet:Open( "SELECT filename FROM testi WHERE iddoc = 217 " , oConnection )
CATCH oErr
MsgAlert( "Error to Open testi" )
END TRY
oRecordset:Fields("filename" ):Value = "new value"
oRecordset:update()
[/code]

but I get :
WINOLE/1007 Argument error: UPDATE

any idea ?

Best regards.

Wzaf
wzaf
 
Posts: 38
Joined: Tue Sep 30, 2008 11:16 am

Re: ADO update() error

Postby Rick Lipkin » Sat Jun 05, 2010 3:47 pm

Perhaps in the select statement filename is a reserved word .. you might try :

oRecordSet:Open( "SELECT [filename] FROM testi WHERE iddoc = 217 " , oConnection

You can test the reserved by "select * from ......" then see if you update() fails .. if it does not fail ... filename may need to be in brackets ..

Just a quick guess ..

Rick Lipkin
User avatar
Rick Lipkin
 
Posts: 2628
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: ADO update() error

Postby wzaf » Sun Jun 06, 2010 7:53 pm

Tank you Rick ,
But I tried with different fields of the table, and I get always the same error:
If I modify the field value, I get error in update method.
In I modify nothing, the update() succeed !.

Best regards

Wzaf
wzaf
 
Posts: 38
Joined: Tue Sep 30, 2008 11:16 am

Re: ADO update() error

Postby James Bott » Sun Jun 06, 2010 8:27 pm

Maybe you don't have rights to write to the table?
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: ADO update() error

Postby wzaf » Sun Jun 06, 2010 8:47 pm

No, James, I have all rights for all DB .

Tank you
Wzaf
wzaf
 
Posts: 38
Joined: Tue Sep 30, 2008 11:16 am

Re: ADO update() error

Postby James Bott » Sun Jun 06, 2010 9:08 pm

Is the recordset empty?

James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: ADO update() error

Postby wzaf » Sun Jun 06, 2010 9:20 pm

No, it is filled with the result of Query: "SELECT filename FROM testi...."

Wzaf
wzaf
 
Posts: 38
Joined: Tue Sep 30, 2008 11:16 am

Re: ADO update() error

Postby Daniel Garcia-Gil » Sun Jun 06, 2010 10:08 pm

wzaf...


did you verify if the SELECT return some value, i means
the select is not empty...
User avatar
Daniel Garcia-Gil
 
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 pm
Location: Isla de Margarita

Re: ADO update() error

Postby wzaf » Sun Jun 06, 2010 10:36 pm

Daniel :
Correct ! the select is not empty....

Wzaf
wzaf
 
Posts: 38
Joined: Tue Sep 30, 2008 11:16 am

Re: ADO update() error

Postby Daniel Garcia-Gil » Mon Jun 07, 2010 2:21 am

kzaf..


test this samples... work fine to me...

download test.mdb

http://www.sitasoft.net/fivewin/samples/testado.rar
Code: Select all  Expand view

#include "FiveWin.Ch"                                                                                
#include "ado.Ch"                                                                                    
                                                                                                     
//----------------------------------------------------------------------------//                    
                                                                                                     
function main()                                                                                      
                                                                                                     
   execConnection()                                                                                  
                                                                                                     
return( 0 )                                                                                          
           
//----------------------------------------------------------------------------//                    
           
                                                                                                     
FUNCTION execConnection                                                                              
                                                                                                     
LOCAL oCon, oRs, oError                                                                              
                                                                                                     
                                                                                                     
oCon := MySQLConnect()                                                                              
                                                                                                     
oRs  := MySQLRecordSet( oCon )                                                                      
                                                                                                     
RETURN( .T. )          

//----------------------------------------------------------------------------//                    

FUNCTION MySQLConnect                                                                                
                                                                                                     
LOCAL oError, oCon, cConnectionString                                                                
                                                                                                     
   TRY                                                                                                  
      oCon := TOleAuto():new( "ADODB.Connection" )                                                      
   CATCH oError                                                                                        
      msgInfo( "No conection" )                                                      
      RETURN( .F. )                                                                                    
   END                                                                                                  
   
   cConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\prg\usuarios\wzaf\test.mdb;User Id=admin;Password=;"
                                                                                                       
   oCon:connectionString := cConnectionString                                                          
   
   TRY                                                                                                  
      oCon:open()                                                                                      
      ? "Connection ok!"                                                                                
                                                                                                       
   CATCH oError                                                                                        
      msgInfo( "No conection" )                                                        
      RETURN( .F. )                                                                                    
   END                                                                                                  
                                                                                                       
RETURN( oCon )                                                                                      

//----------------------------------------------------------------------------//                    


FUNCTION MySQLRecordSet( oCon )                                                                      
                                                                                                     
   LOCAL oRs, oError, cQuerySql                                                                        
                                                                                                       
                                                                                                       
   TRY                                                                                                  
      oRs := TOleAuto():new( "ADODB.RecordSet" )                                                        
                                                                                                       
   CATCH oError                                                                                        
                                                                                                       
      msgStop( "No hay RS" )                                                                            
      oRs := NIL                                                                                        
      RETURN( .F. )                                                                                    
                                                                                                       
   END                                                                                                  
                                                                                                       
   cQuerySql := "SELECT first FROM TEST WHERE id = 3"                                                                    
                                                                                                       
   oRs:cursorLocation := adUseClient // 3                                                              
   oRs:lockType       := adLockOptimistic // 3                                                          
   oRs:cursorType     := adOpenDynamic // 2                                                            
                                                                                                       
   TRY            
      oRs:Open( cQuerySql , oCon )                                                                                          
   CATCH oError                                                                                        
      msgStop( "No Query '" + cQuerySql + "'" )                                                        
      RETURN( .F. )                                                                                    
   END                                                                                                  

   oRs:Fields("first" ):Value := "testing"
   oRs:Update()
RETURN( oRs )                                                                                        

 
User avatar
Daniel Garcia-Gil
 
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 pm
Location: Isla de Margarita

Re: ADO update() error

Postby wzaf » Mon Jun 07, 2010 9:44 am

Daniel,
your code works fine in my environment.
I tried also to recompile and link , and it works!
The only difference is that I use Mysql with "MySQL ODBC 5.1 Driver" and connection string is :
cConnectionString := "Driver={MySQL ODBC 5.1 Driver};Server=localhost;Database=mydb; User=myuser;Password=mypassw"

If I use this connection string in your file , and modify the Select statement to work in my DB, I get the usual error: update error() !

Tank you

Best regards
Wzaf.
wzaf
 
Posts: 38
Joined: Tue Sep 30, 2008 11:16 am

Re: ADO update() error

Postby anserkk » Mon Jun 07, 2010 10:10 am

Try this,

ConnectionString := "Driver={MySQL ODBC 5.1 Driver};Server=127.0.0.1;Port=3306;Database=mydb;User=myuser;Password=mypassw;Option=3;"


The below given code to update a recordset is working fine for me

Code: Select all  Expand view
TRY
   oRecSet:= CreateObject("ADODB.RecordSet")
CATCH oError
   MsgInfo("Failed to Create Recordset")
   ShowSqlError(oError)
   oRecSet:=NIL
   Return .F.
END

cSql:="Select Branch_ID, User_ID, UserName, Password, User_Level, Active from users where Branch_ID="+ltrim(str(oApp:nBranchID))+" and User_Id ="+Alltrim(str(oTmp:nUserId2))
oRecSet:CursorLocation := adUseClient
oRecSet:LockType := adLockOptimistic
oRecSet:CursorType := adOpenDynamic
oRecSet:Source :=cSQL
oRecSet:ActiveConnection(oApp:oConnection)
TRY
   oRecSet:Open()
CATCH oError
   MsgInfo("Failed to Open Recordset of User Details")
   ShowSqlError(oError)
   oRecSet:=NIL
   Return .F.
END
If oRecSet:Eof() .and. oRecSet:Bof()
   MsgInfo("Failed to update the changes, No Records found in retrieved recordset")
   oRecSet:Close()
   Return .F.
Endif

oRecSet:Fields("Password"):Value:=Alltrim(oTmp:cPassword2)
oRecSet:Fields("Active"):Value:=If(oTmp:nStatus2 == 1,"T","F")
oRecSet:UpDate()
SysRefresh()
oRecSet:Close()


Regards
Anser
User avatar
anserkk
 
Posts: 1329
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India

Re: ADO update() error

Postby wzaf » Mon Jun 07, 2010 4:35 pm

Tank you Anser
I tried your code , but now when I try the following :
Code: Select all  Expand view

RecSet:Source :=cSQL
oRecSet:ActiveConnection(oCon)
oRecSet:Open()
 

I get the following error:
WINOLE/1007 Argument error: ACTIVECONNECTION

while if I do :
Code: Select all  Expand view

   oRecSet:Open(cSql, oCon)
 


the creation of RecordSet succeed .

I think there is something wrong in the installation of ADO in my pc.

May Be ?

Best regards
WZaf
wzaf
 
Posts: 38
Joined: Tue Sep 30, 2008 11:16 am

Re: ADO update() error

Postby Daniel Garcia-Gil » Mon Jun 07, 2010 6:08 pm

wzaf...

try change to this line

Code: Select all  Expand view
oRecordSet:Open( "SELECT iddoc, filename FROM testi WHERE iddoc = 217 " , oConnection )


i added iddoc (columns) inside select
User avatar
Daniel Garcia-Gil
 
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 pm
Location: Isla de Margarita

Re: ADO update() error

Postby wzaf » Tue Jun 08, 2010 8:28 am

Tank you very mutch, Daniel.
Now the update works!
It seems that ADO wants in RecordSet the primary key , otherwise it fails when update the DB.
Not only, but when I tried to update (and getting errors), the table where modified in more than one row, not only the row holding the '217' key!!! .


Best regards,
Wzaf
wzaf
 
Posts: 38
Joined: Tue Sep 30, 2008 11:16 am


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 13 guests