Hi all Friends
How can I open a table in .mdb file with HMG?
Thanks in Advance,
Apichit
How to open a table in .mdb
Moderator: Rathinagiri
- danielmaximiliano
- Posts: 2763
- Joined: Fri Apr 09, 2010 4:53 pm
- DBs Used: DBF
- Location: Argentina
- Contact:
Re: How to open a table in .mdb
HI :
Sample :
Code: Select all
#include "adordd.ch"
USE test2.mdb VIA "ADORDD" TABLE "table1"Code: Select all
/*
* MINIGUI - Harbour Win32 GUI library Demo
*
* Copyright 2002-2007 Roberto Lopez <harbourminigui@gmail.com>
* http://harbourminigui.googlepages.com/
*
* Based on ADORDD sample included in Harbour distribution
*/
#include "adordd.ch"
#include "minigui.ch"
Function Main()
DEFINE WINDOW Form_1 ;
AT 0,0 ;
WIDTH 640 HEIGHT 480 ;
TITLE 'MiniGUI AdoRDD Demo' ;
MAIN NOMAXIMIZE ;
ON INIT OpenTable() ;
ON RELEASE CloseTable()
@ 10,10 BROWSE Browse_1 ;
WIDTH 610 ;
HEIGHT 390 ;
HEADERS { 'First' , 'Last' , 'Birth' , 'Age' } ;
WIDTHS { 150 , 150 , 100 , 100 } ;
WORKAREA Test2 ;
FIELDS { 'Test2->First' , 'Test2->Last' , 'Test2->Birth' , 'Test2->Age' } ;
JUSTIFY { 0 , 0 , 2 , 1 }
END WINDOW
CENTER WINDOW Form_1
Form_1.Browse_1.SetFocus
ACTIVATE WINDOW Form_1
Return nil
Procedure OpenTable
IF !IsWinNT() .AND. !CheckODBC()
MsgStop( 'This Program Runs In Win2000/XP Only!', 'Stop' )
ReleaseAllWindows()
ENDIF
IF !FILE('test2.mdb')
CreateTable()
ENDIF
USE test2.mdb VIA "ADORDD" TABLE "table1"
IF EMPTY( test2->( LastRec() ) )
APPEND BLANK
test2->First := "Homer"
test2->Last := "Simpson"
test2->Birth := date() - 45 * 365
test2->Age := 45
APPEND BLANK
test2->First := "Lara"
test2->Last := "Kroft"
test2->Birth := date() - 32 * 365
test2->Age := 32
ENDIF
GO TOP
Return
Procedure CloseTable
USE
Return
Procedure CreateTable
DbCreate( "test2.mdb;table1", { { "FIRST", "C", 10, 0 },;
{ "LAST", "C", 10, 0 },;
{ "BIRTH", "D", 8, 0 },;
{ "AGE", "N", 8, 0 } }, "ADORDD" )
Return
Static Function CheckODBC()
LOCAL oReg, cKey := ""
OPEN REGISTRY oReg KEY HKEY_LOCAL_MACHINE ;
SECTION "Software\Microsoft\DataAccess"
GET VALUE cKey NAME "Version" OF oReg
CLOSE REGISTRY oReg
Return !EMPTY(cKey)
*´¨)
¸.·´¸.·*´¨) ¸.·*¨)
(¸.·´. (¸.·` *
.·`. Harbour/HMG : It's magic !
(¸.·``··*
Saludos / Regards
DaNiElMaXiMiLiAnO
Whatsapp. := +54901169026142
Telegram Name := DaNiElMaXiMiLiAnO
Telegram invitation https://t.me/HMGWorkspace
¸.·´¸.·*´¨) ¸.·*¨)
(¸.·´. (¸.·` *
.·`. Harbour/HMG : It's magic !
(¸.·``··*
Saludos / Regards
DaNiElMaXiMiLiAnO
Whatsapp. := +54901169026142
Telegram Name := DaNiElMaXiMiLiAnO
Telegram invitation https://t.me/HMGWorkspace
- salamandra
- Posts: 311
- Joined: Thu Jul 31, 2008 8:33 pm
- DBs Used: DBF, MySQL, SQL
- Location: Brazil
Re: How to open a table in .mdb
Hi apichit
,
Take a look at the sample located at ..\SAMPLES\RDD.SQL\mdb
Think it´s what you need.
[]´s Salamandra
Take a look at the sample located at ..\SAMPLES\RDD.SQL\mdb
Think it´s what you need.
[]´s Salamandra
There is one time in which is crucial awakening. That time is now. ( Buddha )
Re: How to open a table in .mdb
Thank you very much Danielmaximiliano, Salamandra
Re: How to open a table in .mdb
My favorite way is using SQLMIX. It works very well.
From Harbours contrib\sddodbc\tests folder (the examples are for command line CUI but you can easily adapt it to HMG):
Other approach (IMHO a bit more complex and for MySQL although you can do the same for MDB or any database connected via ODBC):
From Harbours contrib\sddodbc\tests folder (the examples are for command line CUI but you can easily adapt it to HMG):
Code: Select all
/*
* $Id: test1.prg 18886 2013-03-02 01:24:02Z vszakats $
*/
#require "rddsql"
#require "sddodbc"
#include "simpleio.ch"
REQUEST SDDODBC, SQLMIX
PROCEDURE Main()
#if defined( __HBSCRIPT__HBSHELL )
rddRegister( "SQLBASE" )
rddRegister( "SQLMIX" )
hb_SDDODBC_Register()
#endif
Set( _SET_DATEFORMAT, "yyyy-mm-dd" )
rddSetDefault( "SQLMIX" )
? "Connect:", rddInfo( RDDI_CONNECT, { "ODBC", "DBQ=" + hb_DirBase() + "..\..\hbodbc\tests\test.mdb;Driver={Microsoft Access Driver (*.mdb)}" } )
? "Use:", dbUseArea( .T., , "select * from test", "test" )
? "Alias:", Alias()
? "DB struct:", hb_ValToExp( dbStruct() )
Inkey( 0 )
Browse()
INDEX ON FIELD->SALARY TO salary
dbGoTop()
Browse()
dbCloseArea()
RETURNCode: Select all
/*
* $Id: test2.prg 18886 2013-03-02 01:24:02Z vszakats $
*/
#require "rddsql"
#require "sddodbc"
#include "simpleio.ch"
REQUEST SQLMIX, SDDODBC
PROCEDURE Main()
LOCAL nConnection, nI, aI
Set( _SET_DATEFORMAT, "yyyy-mm-dd" )
rddSetDefault( "SQLMIX" )
nConnection := rddInfo( RDDI_CONNECT, { "ODBC", "Server=localhost;Driver={MySQL ODBC 5.1 Driver};dsn=;User=test;database=test;" } )
IF nConnection == 0
? "Unable connect to server", rddInfo( RDDI_ERRORNO ), rddInfo( RDDI_ERROR )
RETURN
ENDIF
? nConnection
? rddInfo( RDDI_EXECUTE, "DROP TABLE country" )
? rddInfo( RDDI_EXECUTE, "CREATE TABLE country (CODE char(3), NAME char(50), RESIDENTS int(11))" )
? rddInfo( RDDI_EXECUTE, "INSERT INTO country values ('LTU', 'Lithuania', 3369600),('USA', 'United States of America', 305397000), ('POR', 'Portugal', 10617600), ('POL', 'Poland', 38115967), ('AUS', 'Australia', 21446187), ('FRA', 'France', 64473140), ('RUS', 'Russia', 141900000)" )
? dbUseArea( .T., , "SELECT * FROM country", "country" )
? "LASTREC:", LastRec()
DO WHILE ! Eof()
aI := Array( FCount() )
FOR nI := 1 TO FCount()
aI[nI] := FieldGet( nI )
NEXT
? RecNo(), hb_ValToExp( aI )
dbSkip()
ENDDO
? "LASTREC:", LastRec()
dbCloseAll()
RETURN
Last edited by Hazael on Thu Mar 21, 2013 5:59 am, edited 1 time in total.
Harbour | GTWVT | MingW | Visual Studio Code
- danielmaximiliano
- Posts: 2763
- Joined: Fri Apr 09, 2010 4:53 pm
- DBs Used: DBF
- Location: Argentina
- Contact:
Re: How to open a table in .mdb
[quote=Qatan ]My favorite way is using SQLMIX. It works very well.[/quote]
Muchas gracias Qatan por la info
Qatan thank you very much for the info
Muchas gracias Qatan por la info
Qatan thank you very much for the info
*´¨)
¸.·´¸.·*´¨) ¸.·*¨)
(¸.·´. (¸.·` *
.·`. Harbour/HMG : It's magic !
(¸.·``··*
Saludos / Regards
DaNiElMaXiMiLiAnO
Whatsapp. := +54901169026142
Telegram Name := DaNiElMaXiMiLiAnO
Telegram invitation https://t.me/HMGWorkspace
¸.·´¸.·*´¨) ¸.·*¨)
(¸.·´. (¸.·` *
.·`. Harbour/HMG : It's magic !
(¸.·``··*
Saludos / Regards
DaNiElMaXiMiLiAnO
Whatsapp. := +54901169026142
Telegram Name := DaNiElMaXiMiLiAnO
Telegram invitation https://t.me/HMGWorkspace