ODBC

Post Reply
User avatar
Silvio
Posts: 3107
Joined: Fri Oct 07, 2005 6:28 pm
Location: Teramo,Italy

ODBC

Post by Silvio »

I have xharbour and fwh
I must use a MDB file
On this Mdb file there is a Table called Prodotti
I must open it and modify all



I try it

Code: Select all

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

   // Open the table

   oDbf := TDbOdbcDirect():new( "SELECT * FROM prodotti" , oOdbc)

  if oOdbc:IsError()
      oOdbc:ShowErrorList()
      oOdbc:aErrors := {}
      oDbf:End()
      return nil
   endif

   oDbf:Open()
   oDbf:Complete()

  // Listbox


        DEFINE DIALOG oDlg FROM 3, 3 TO 28, 79 TITLE "Gestione Prodotti"
         @ 0,  1 SAY " &List"  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 EditClient( oLbx, .t. )
   @ 9,  8 BUTTON "&Modifica" OF oDlg  SIZE 40, 12 EditClient( oLbx, .f. )
   @ 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)

Now I must convert this func but I cannot Know How can I make it

Code: Select all

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 nil

Can You help me pls
Post Reply