Ado & MDB

Ado & MDB

Postby Silvio » Fri Oct 28, 2005 5:45 pm

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
User avatar
Silvio
 
Posts: 3107
Joined: Fri Oct 07, 2005 6:28 pm
Location: Teramo,Italy

ADO

Postby byron.hopp » Sun Nov 06, 2005 4:15 pm

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 ----
#define adOpenForwardOnly 0
#define adOpenKeyset 1
#define adOpenDynamic 2
#define adOpenStatic 3


//---- LockTypeEnum Values ----
#define adLockReadOnly 1
#define adLockPessimistic 2
#define adLockOptimistic 3
#define adLockBatchOptimistic 4


//---- CursorLocationEnum Values ----
#define adUseServer 2
#define adUseClient 3

//---- DataTypeEnum Values ----
#define adEmpty 0
#define adTinyInt 16
#define adSmallInt 2
#define adInteger 3
#define adBigInt 20
#define adUnsignedTinyInt 17
#define adUnsignedSmallInt 18
#define adUnsignedInt 19
#define adUnsignedBigInt 21
#define adSingle 4
#define adDouble 5
#define adCurrency 6
#define adDecimal 14
#define adNumeric 131
#define adBoolean 11
#define adError 10
#define adUserDefined 132
#define adVariant 12
#define adIDispatch 9
#define adIUnknown 13
#define adGUID 72
#define adDate 7
#define adDBDate 133
#define adDBTime 134
#define adDBTimeStamp 135
#define adBSTR 8
#define adChar 129
#define adVarChar 200
#define adLongVarChar 201
#define adWChar 130
#define adVarWChar 202
#define adLongVarWChar 203
#define adBinary 128
#define adVarBinary 204
#define adLongVarBinary 205
#define adChapter 136
#define adFileTime 64
#define adPropVariant 138
#define adVarNumeric 139
#define adArray &H2000
Thanks,
Byron Hopp
Matrix Computer Services
byron.hopp
 
Posts: 382
Joined: Sun Nov 06, 2005 3:55 pm
Location: Southern California, USA

Postby Silvio » Sun Nov 06, 2005 4:56 pm

I try this
Code: Select all  Expand view
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)




Now I must convert the EditClient( oLbx, .t. ) function but I cannot How I can make it

this the code


Code: Select all  Expand view
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
User avatar
Silvio
 
Posts: 3107
Joined: Fri Oct 07, 2005 6:28 pm
Location: Teramo,Italy

TO Byron

Postby Silvio » Wed Nov 09, 2005 10:49 am

I need I test sample with addneww func
Pls Help me
Regards
User avatar
Silvio
 
Posts: 3107
Joined: Fri Oct 07, 2005 6:28 pm
Location: Teramo,Italy


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 59 guests