I want use a file MDB on Xharbour( &fw) with ado or another class
I want open a table and make insert,mod,search and print
there is some example to make it ?
Regards
Silvio
Falconi Silvio
I want use a file MDB on Xharbour( &fw) with ado or another class
I want open a table and make insert,mod,search and print
there is some example to make it ?
Regards
Silvio
First of all, you need to make sure MDAC is installed on your workstation. One way to do this is as follows:
Create a blank file with the extention .UDL (i.e. test.udl).
This file must be blank.
Either click on the file, or from the command prompt type
Start Test.udl
If a data connection wizard appears, then you have MDAC.
If this does not work, then download MDAC from the microsoft website.
btw, if you complete the connection wizard, it will place a valid ADO connection string in the (no longer empty) file. This can be utilized with your code.
Not tested code...
oRs := CreateObject("ADODB.RecordSet")
oRs:CursorLocation := adUseClient
oRs:LockType := adLockOptimistic
oRs:CursorType := adOpenDynamic
oRs:ActiveConnection := 'your connection string copied from the UDL file'
oRs:Source := 'Select * from MyTable' // or other valid sql.
Once you have filled your recordset with data you can utilize the following methods to navigate, (much more information on the Web) Google search for 'ADO RecordSet'
oRs:MoveFirst() // DbGoTop()
oRs:MoveNext() // DbSkip()
oRs:MoveLast() // DbGoBottom()
oRs:AddNew() // DbAppend()
oRs:Update() // DbCommit() but is required to complete add.
Replace...
oRs:Fields("MyCharField"):Value := 'MyValue'
I hope this helps get you started
might come in handy constants...
//---- FileOpenEnum Values ----
//---- LockTypeEnum Values ----
//---- CursorLocationEnum Values ----
//---- DataTypeEnum Values ----
function Prodotti()
local oBCli , oWChld ,oDlg ,oWnd ,oLbx
Local oDbf
local aData := {}
Local nFor, oOdbc
SET 3D LOOK ON
oOdbc := TOdbc():New("Database di Microsoft Access", "", "")
If !oOdbc:lSuccess
oOdbc:ShowErrorList("Sessione ODBC non inizializzata , Errore...")
oOdbc:End()
return nil
Endif
// Apro la tabella direttamente
oDbf := TDbOdbcDirect():new( "SELECT * FROM prodotti" , oOdbc)
if oOdbc:IsError()
oOdbc:ShowErrorList()
oOdbc:aErrors := {}
oDbf:End()
return nil
endif
oDbf:Open()
oDbf:Complete()
// Creo il list box e i bottoni
DEFINE DIALOG oDlg FROM 3, 3 TO 28, 79 TITLE "Gestione Prodotti"
@ 0, 1 SAY " &Demo" OF oDlg
@ 1, 1 LISTBOX oLbx FIELDS str(oDbf:FieldGet(1)), oDbf:FieldGet(2),oDbf:FieldGet(5) ;
HEADER "ID", "Codice", "Prodotto" ;
SIZE 284, 137 OF oDlg
@ 9, 1 BUTTON "&Nuovo" OF oDlg SIZE 40, 12 action EditClient( oLbx, .t. )
@ 9, 8 BUTTON "&Modifica" OF oDlg SIZE 40, 12
@ 9, 15 BUTTON "&Cancella" OF oDlg SIZE 40, 12
@ 9, 22 BUTTON "&Ricerca" OF oDlg SIZE 40, 12
@ 9, 29 BUTTON "&Stampa" OF oDlg SIZE 40, 12
@ 9, 40 BUTTON "&Uscita" OF oDlg ACTION oDlg:End() SIZE 40, 12
ACTIVATE DIALOG oDlg
oDbf:End()
oOdbc:End()
RETURN (NIL)static function EditClient( oLbx, lAppend )
local cName
local cAddress
local cPhone
local nOldRec := RecNo()
DEFAULT lAppend := .f.
if lAppend
GOTO BOTTOM
SKIP
endif
cName = Clientes->Nombre && field0001
cAddress = Clientes->Direccion && field0002
cPhone = Clientes->Telefono && field0003
DEFINE DIALOG oDlg FROM 8, 2 TO 25, 65 ;
TITLE If( lAppend, "New Customer", "Customer Update" )
@ 1, 1 SAY "&Name:" OF oDlg
@ 1, 6 GET cName OF oDlg
@ 2, 1 SAY "&Address:" OF oDlg
@ 2, 6 GET cAddress OF oDlg
@ 3.5, 23 SAY "&Phone:" OF oDlg
@ 4, 21 GET cPhone OF oDlg SIZE 60, 11 PICTURE "@R 99-999-9999999"
@ 6, 9 BUTTON "&Acept" OF oDlg SIZE 50, 12 ACTION ( lSave := .t. , oDlg:End() )
@ 6, 19 BUTTON "&Cancel" OF oDlg SIZE 50, 12 ACTION oDlg:End()
ACTIVATE DIALOG oDlg CENTERED
if lSave .and. !empty( cName )
if lAppend
APPEND BLANK
endif
Clientes->Nombre := cName
Clientes->Direccion := cAddress
Clientes->Telefono := cPhone
oLbx:Refresh() // We want the ListBox to be repainted
else
if Empty( cName ) .and. lSave
MsgAlert( "Please write a name" )
endif
GOTO nOldRec
endif
return nilI need I test sample with addneww func
Pls Help me
Regards