Read mdb file

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

Post Reply
User avatar
BeGeS
Posts: 110
Joined: Fri Jul 14, 2017 10:45 am
DBs Used: DBF
Location: La Mancha, Spain
Has thanked: 29 times
Been thanked: 21 times

Read mdb file

Post by BeGeS » Sun Mar 04, 2018 9:28 pm

Hi friends.

I need to read an Access file (.mdb). I've looked around and there are quite a few things, but... I think the trees do not let me see the forest.

What I want is basic: open the file, read the fields of the different registers to save that information in some variables, and close the file.

A simple example would suffice.

Thank you very much. ;)
I get by with a little help from my friends

User avatar
bpd2000
Posts: 999
Joined: Sat Sep 10, 2011 4:07 am
Location: India
Has thanked: 150 times
Been thanked: 65 times

Post by bpd2000 » Mon Mar 05, 2018 3:59 am

Working with .DBF file is very simple through HMG, however, other than DbF file you have to use AdoRDD/SQL
Visit,
http://hmgforum.com/viewtopic.php?f=9&t ... base#p5044

it may help you, there is a good working example from Mustafa

More info on DBF, Access MDB, and SQL database visit

https://db-engines.com/en/system/Micros ... er%3BdBASE
BPD
Convert Dream into Reality through HMG

User avatar
serge_girard
Posts: 2029
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Has thanked: 378 times
Been thanked: 87 times
Contact:

Post by serge_girard » Mon Mar 05, 2018 8:35 am

Beges,

This may help a little:

Code: Select all

#include "hmg.ch"
#include "Common.ch"
#include "fileio.ch"
#include "error.ch"
#include "Directry.ch"
#include 'hbclass.ch'




FUNCTION MAIN()
/******************/
PUBLIC oConnexion	:= OpenConnection("C:\SOME.MDB")
PUBLIC oUser		:= TUUser()	

SET PRINTER TO OUTPUT.TXT  
SET PRINTER ON 
SET CONSOLE OFF



o := openrecordset( oConnexion, "SELECT * FROM some_mdb_database ")
if o:Recordcount > 0
	do while !o:eof()
		?	o:Fields('some_fld1'):Value
		??	o:Fields('some_fld2'):Value
		??	o:Fields('some_fld3'):Value
		??	o:Fields('some_fld4'):Value
		??	o:Fields('some_fld5'):Value
		??	o:Fields('some_fld6'):Value
		??	o:Fields('some_fld7'):Value
		??	o:Fields('some_fld8'):Value

		o:MoveNext()
	enddo
endif
//o := Execute_Q( oConnexion, "DELETE FROM some_mdb_database WHERE some_fld1 = '??' ")
//o := openrecordset( oConnexion, "INSERT INTO some_mdb_database (some_fld1 , some_fld2)  VALUES ('z1', 'z2') ")

o:close()
SET PRINTER TO  
SET PRINTER OFF 
SET CONSOLE ON

RETURN



CLASS TUUser
/*************/
DATA cKey, cUser, cName INIT ""
DATA nId, nIdAccess     INIT 0
END CLASS

As I don't have mdb files I cannot test it!

Serge

User avatar
BeGeS
Posts: 110
Joined: Fri Jul 14, 2017 10:45 am
DBs Used: DBF
Location: La Mancha, Spain
Has thanked: 29 times
Been thanked: 21 times

Post by BeGeS » Mon Mar 05, 2018 9:54 am

bpd2000 wrote:
Mon Mar 05, 2018 3:59 am
Working with .DBF file is very simple through HMG, however, other than DbF file you have to use AdoRDD/SQL
Visit,
http://hmgforum.com/viewtopic.php?f=9&t ... base#p5044

it may help you, there is a good working example from Mustafa

More info on DBF, Access MDB, and SQL database visit

https://db-engines.com/en/system/Micros ... er%3BdBASE
Thanks, BPD. But now I do not need technical features but a simple and practical example to read an mdb file.

As for dbf files, I have learned something in the last twenty-five years. :)
I get by with a little help from my friends

User avatar
BeGeS
Posts: 110
Joined: Fri Jul 14, 2017 10:45 am
DBs Used: DBF
Location: La Mancha, Spain
Has thanked: 29 times
Been thanked: 21 times

Post by BeGeS » Mon Mar 05, 2018 9:55 am

serge_girard wrote:
Mon Mar 05, 2018 8:35 am
As I don't have mdb files I cannot test it!
:D

Thanks, Serge.

I'll try it tonight and then I'll tell you. ;)
I get by with a little help from my friends

User avatar
mustafa
Posts: 629
Joined: Fri Mar 20, 2009 11:38 am
Location: Alicante - Spain
Been thanked: 52 times

Post by mustafa » Mon Mar 05, 2018 10:18 am

Hola BeGeS:
Mira si te podría servir este sample --> "Adordd_Sample.zip"
viewtopic.php?f=9&t=837&hilit=adordd&start=10
Saludos Mustafa
*------------------------------------- Google --------------------------------------*
Hello BeGeS:
See if you could use this sample -> "Adordd_Sample.zip"
viewtopic.php?f=9&t=837&hilit=adordd&start=10
Regards Mustafa

EduardoLuis
Posts: 551
Joined: Tue Jun 04, 2013 6:33 pm
Location: Argentina
Been thanked: 32 times

Post by EduardoLuis » Mon Mar 05, 2018 9:37 pm

Hi Mustafa:

I've test your sample posted, but it give an error when compiling, exactly:
APOYO.PRG : USE test.mdb VIA "ADORDD" TABLE "test" alias test
I try compiling under 3.44 and previous versions till 3.40 , and allways the same error.
If you please, tell me how to solve it.-
With regards.
Eduardo

User avatar
mustafa
Posts: 629
Joined: Fri Mar 20, 2009 11:38 am
Location: Alicante - Spain
Been thanked: 52 times

Post by mustafa » Tue Mar 06, 2018 11:38 am

Hola EduardoLuis:
He comprobado lo que me dices que está dado Error
he bajado el fichero zip ---> Adordd_Sample.zip
viewtopic.php?f=9&t=837&hilit=adordd&start=10
he utilizado el build.3.4.3.bat que esta dentro del la Carpeta -> [Adordd_Sample]
contenido del fichero bat
*--------------- build.3.4.3.bat ------------------------*
@ECHO OFF
call c:\hmg.3.4.3\build.bat Sample_Adordd.prg %*
*---------------------------------------------------------*
la ruta tie que ser donde este instalado en tu ordenador
HMG 343 he Compilado y no me está dando ningún Error
la compilación tiene que ser en modo de 32 bits.
He probado HMG 344-64 bits y me está dando Error
*---------------- ERROR -------------*
Date:2018-03-06 Time: 12:23:54
Error SQLBASE/1901 Not connected
Called from DBUSEAREA(0)
Called from MAIN(92)
*-------------------------------------*
Creo que es por la mención de:

Code: Select all

RDDSETDEFAULT( "SQLMIX" )
SET( 4, "yyyy-mm-dd" )
RDDINFO( RDDI_CONNECT, { "ODBC", "DBQ="  + "test.mdb;Driver={Microsoft Access Driver (*.mdb)}" } )
DBUSEAREA( .T.,, "select * from test", "test" ) 
por el tipo de Driver de Microsoft Access Driver ? no lo se si por que es a 32 bits
Tambien tengo instalado --> Microsoft Office Access 2007
en HMG 343 a 32 bits me funciona y me da Error HMG 344 64 bits
No tengo instalado para probar HMG 344 32 bits

Podría ser el Driver si no está instalado ver:
https://techblog.aimms.com/2014/10/27/i ... ach-other/
https://www.microsoft.com/en-us/downloa ... x?id=13255

Saludos
Mustafa
*------------------------------------------ Google -------------------------------------------*

Hello EduardoLuis:
I have checked what you tell me that is given Error
I have downloaded the zip file ---> Adordd_Sample.zip
viewtopic.php?f=9&t=837&hilit=adordd&start=10
I used the build.3.4.3.bat that is inside the folder -> [Adordd_Sample]
content of the bat file
*--------------- build.3.4.3.bat ------------------------*
@ECHO OFF
call c:\hmg.3.4.3\build.bat Sample_Adordd.prg % *
*---------------------------------------------------------*
the route has to be where this
installed on your HMG 343 computer I have compiled and it is not giving me any error
the compilation has to be in 32-bit mode.
I've tried HMG 344-64 bits and it's giving me Error
*---------------- ERROR -------------*
Date: 2018-03-06 Time: 12:23:54
SQLBASE / 1901 Not connected error
Called from DBUSEAREA (0)
Called from MAIN (92)
*------------------------------------*
I think it's because of the mention of:

Code: Select all

RDDSETDEFAULT ("SQLMIX")
SET (4, "yyyy-mm-dd")
RDDINFO (RDDI_CONNECT, {"ODBC", "DBQ =" + "test.mdb; Driver = {Microsoft Access Driver (* .mdb)}"})
DBUSEAREA (.T. ,, "select * from test", "test")
by the type of Microsoft Access Driver Driver? I do not know if it's 32 bits
I also have installed -> Microsoft Office Access 2007
in HMG 343 to 32 bits it works for me and it gives me Error HMG 344 64 bits
I do not have installed to test HMG 344 32 bits

It could be the Driver if it is not installed see:
https://techblog.aimms.com/2014/10/27/i ... ach-other/
https://www.microsoft.com/en-us/downloa ... x?id=13255
Regards

Mustafa

EduardoLuis
Posts: 551
Joined: Tue Jun 04, 2013 6:33 pm
Location: Argentina
Been thanked: 32 times

Post by EduardoLuis » Tue Mar 06, 2018 1:31 pm

Hi Mustafa:

I've download the zip and installed on a different folder not inside HMG_3.44
I'll try to do like you.
Thanks
Eduardo

Post Reply