Problem with Access recordset

Problem with Access recordset

Postby James Bott » Wed Nov 26, 2008 4:10 pm

I am having a problem with an Access recordset. I can get the connection and the oRS:eof works, but both oRS:FieldGet() and oRS:Fields() error out with an UKNOWN NAME error. Any ideas?

Here is the actual error:

Error description: Error ADODB.Recordset/6 DISP_E_UNKNOWNNAME: FIELDGET

Here is my code:

Code: Select all  Expand view
#include "Fivewin.ch"
#include "Tcbrowse.ch"

#define TABLE "ERROR_CODES"


FUNCTION MAIN()

    LOCAL oRs, oErr
    LOCAL cFile:= "TIPDATA.MDB"

    oRs = CREATEOBJECT( "ADODB.Recordset" )

    TRY
        oRS:Open( "SELECT * FROM " + TABLE, "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=tipdata.mdb", 1, 3 )
    CATCH oErr
        ? oErr:Description
        RETURN NIL
    END TRY

    msgInfo( oRS:eof )  // OK
    msgInfo( oRS:FieldGet(1) )  // Error
    msgInfo( oRS:Fields("ERROR_CODE"):value ) // Error
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Postby James Bott » Wed Nov 26, 2008 4:56 pm

OK, I have found that oRS:FieldGet(1) is invalid syntax, I guess. I found this example somewhere, but it continues to error out.

All of a sudden, oRS:Fields("ERROR_CODE") started working and I can't figure out why.

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

Postby Rochinha » Wed Nov 26, 2008 5:32 pm

Bott,

Change:
Code: Select all  Expand view
FUNCTION MAIN()

    LOCAL oRs


With and try
Code: Select all  Expand view
FUNCTION MAIN()

    PUBLIC oRs
Rochinha
 
Posts: 310
Joined: Sun Jan 08, 2006 10:09 pm
Location: Brasil - Sao Paulo

Postby Armando » Wed Nov 26, 2008 5:48 pm

James:

With MySql connection i use this code:

Code: Select all  Expand view
TRY
   oRsEmp   :=   TOleAuto():New("adodb.recordset")
CATCH oError
   MsgStop( "No se ha podido crear el RECORDSET de Empresas !", oApp:cAplicacion)
   ShowError(oError)
   oRsEmp   :=   NIL
   RETURN(.F.)
END

oRsEmp:CursorLocation   := adUseClient
oRsEmp:LockType         := adLockOptimistic
oRsEmp:CursorType         := adOpenDynamic
oRsEmp:Source         := "SELECT " +;
                              "* " +;
                           "FROM " +;
                              "empresa"
oRsEmp:ActiveConnection(oApp:oCon)

TRY
   oRsEmp:Open()
CATCH oError
   MsgStop( "No se ha podido abrir el RECORDSET de Empresas !", oApp:cAplicacion)
   ShowError(oError)
   RETURN(.F.)
END

IF oRsEmp:BOF() .AND. oRsEmp:EOF()
ELSE
   oRsEmp:MoveFirst()
ENDIF


Regards
SOI, s.a. de c.v.
estbucarm@gmail.com
http://www.soisa.mex.tl/
http://sqlcmd.blogspot.com/
Tel. (722) 174 44 45
Carpe diem quam minimum credula postero
User avatar
Armando
 
Posts: 3211
Joined: Fri Oct 07, 2005 8:20 pm
Location: Toluca, México

Postby Armando » Wed Nov 26, 2008 5:52 pm

James:

I forgot, this is the right sintaxis.

Code: Select all  Expand view
oRsEmp:Fields("EMP_PDI"):Value


Where the "EMP_PDI" text is the field name of the EMPRESAS table in the oRsEmp Record set.

I hope this can help you.

Regards
SOI, s.a. de c.v.
estbucarm@gmail.com
http://www.soisa.mex.tl/
http://sqlcmd.blogspot.com/
Tel. (722) 174 44 45
Carpe diem quam minimum credula postero
User avatar
Armando
 
Posts: 3211
Joined: Fri Oct 07, 2005 8:20 pm
Location: Toluca, México

Postby Rochinha » Wed Nov 26, 2008 11:18 pm

Bott,

The table is empty?
Rochinha
 
Posts: 310
Joined: Sun Jan 08, 2006 10:09 pm
Location: Brasil - Sao Paulo

Postby James Bott » Thu Nov 27, 2008 5:35 am

Thanks everyone for the responses. However, everything in the example posted in the first message is now working except the oRS:fieldGet( 1 ), which I think must be invalid syntax.

This wasn't working, then it started working.

oRS:Fields("ERROR_CODE"):Value

There must have been something different when it wasn't working but I don't know what it was.

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

Postby anserkk » Sat Dec 13, 2008 10:13 am

Dear Mr.James,

If your field ERROR_CODE is of type VarChar and if you have not done an alltrim while adding/replacing data to this column in the table, then you may get similiar errors when you try to manipulate data of this particular column.

I experienced a similiar problem with MySQl and ADODB

Regards

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

Postby James Bott » Sun Dec 14, 2008 3:23 pm

Anser,

Thanks for the tip. Everything is working fine now. I must have had a bug in my code that I didn't notice, and accitdentally fixed, because all of a sudden it started working.

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


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 96 guests