Problem with Access recordset

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

Problem with Access recordset

Post by James Bott »

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

#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: 4654
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Post by James Bott »

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
Rochinha
Posts: 309
Joined: Sun Jan 08, 2006 10:09 pm
Location: Brasil - Sao Paulo
Contact:

Post by Rochinha »

Bott,

Change:

Code: Select all

FUNCTION MAIN() 

    LOCAL oRs
With and try

Code: Select all

FUNCTION MAIN() 

    PUBLIC oRs
User avatar
Armando
Posts: 2479
Joined: Fri Oct 07, 2005 8:20 pm
Location: Toluca, México
Contact:

Post by Armando »

James:

With MySql connection i use this code:

Code: Select all

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: 2479
Joined: Fri Oct 07, 2005 8:20 pm
Location: Toluca, México
Contact:

Post by Armando »

James:

I forgot, this is the right sintaxis.

Code: Select all

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
Rochinha
Posts: 309
Joined: Sun Jan 08, 2006 10:09 pm
Location: Brasil - Sao Paulo
Contact:

Post by Rochinha »

Bott,

The table is empty?
User avatar
James Bott
Posts: 4654
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Post by James Bott »

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
anserkk
Posts: 1280
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India

Post by anserkk »

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
James Bott
Posts: 4654
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Post by James Bott »

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
Post Reply