Pasar datos de una tabla DBF a una de access

Re: Pasar datos de una tabla DBF a una de access

Postby nageswaragunupudi » Fri Aug 08, 2014 1:03 am

Creating and openinng Access Database with passwords. ( Both mdb and accdb )

Creating an access database with password:
FW_CreateMDB( "c:\fwh\samples\mdbpwd.mdb", "mypassword" )

Opening:
1) Using connection string:

cStr := "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\fwh\samples\mdbpwd.mdb;Jet OLEDB:Database Password=mypassword;"
oCn := FW_OpenAdoConnection( cStr, .t. )

2) Using FWH Connection Spec:

oCn := FW_OpenAdoConnection( "c:\fwh\samples\mdbpwd.mdb,mypasword", .t. )

3) Using FWH command syntax

ADOCONNECT oCn TO MSACCESS c:\fwh\samples\mdbpwd.mdb PASSWORD mypassword
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10625
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Pasar datos de una tabla DBF a una de access

Postby nageswaragunupudi » Fri Aug 08, 2014 2:24 am

Migrating from Access to MySql

Please try this program:
Code: Select all  Expand view
#include "fivewin.ch"
#include "adodef.ch"

function Main()

   local oCn, oRs

   ? "Connecting to mysql server"
   ADOCONNECT oCn TO MYSQL SERVER localhost DATABASE FWH USER root PASSWORD yourpassword
   if oCn == nil .or. oCn:State == 0
      ? "Fail to connect to mysql"
      return nil
   endif

   ? "Importing CUSTOMER table from c:\fwh\samples\xbtrest.mdb"
   MDB2MYSQL( oCn, "c:\fwh\samples\xbrtest.mdb", "CUSTOMER" )

   ? "Browse the imported table"
   oRs   := FW_OpenRecordSet( oCn, "CUSTOMER" )
   XBROWSER oRs AUTOSORT
   oRs:Close()
   oCn:Close()

return nil

function MDB2MYSQL( oCnMySql, cMdb, cTable )

   local oCnMDB, oRs, aRows, aStruct, lHasAutoInc, aCols
   local cSql, cExecSql, nRow, n
   local nBatchSize := 100

   oCnMDB   := FW_OpenAdoConnection( cMdb, .t. )
   oRs      := FW_OpenRecordSet( oCnMDB, cTable )
   aStruct  := FWAdoStruct( oRs )
   if oRs:RecordCount() > 0
      aRows    := oRs:GetRows()
      oRs:MoveFirst()
      oRs:Close()
      oCnMDB:Close()
   endif
   TRY
      oCnMySQL:Execute( "DROP TABLE " + cTable )
   CATCH
   END

   lHasAutoInc := ( aStruct[ 1, 2 ] == '+' )
   FWAdoCreateTable( cTable, aStruct, oCnMySQL, !lHasAutoInc )
   aCols    := ArrTranspose( aStruct )[ 1 ]
   ADel( aCols, 1, .t. )
   AEval( aCols, { |c,i| aCols[ i ] := Chr(96) + c + Chr(96) } )
   aCols    := FW_ArrayAsList( aCols )
   cSql     := "INSERT INTO " + cTable + " ( " + aCols + " ) VALUES "

   n     := 0
   for nRow := 1 to Len( aRows )

      aCols    := aRows[ nRow ]
      if lHasAutoInc
         ADel( aCols, 1, .t. )
      endif
      aCols    := FW_ValToSQL( aCols )

      if n == 0
         cExecSQL    := cSql + aCols
      else
         cExecSQL    += "," + aCols
      endif

      if n >= nBatchSize .or. nRow >= Len( aRows )
         TRY
            oCnMySQL:Execute( cExecSQL )
         CATCH
            FW_ShowAdoError()
            QUIT
         END
         n  := 0
      else
         n++
      endif

   next nRow

return nil
 


In the above program, please replace your servername, database. username and password.

If the mdb file is password protected:
Code: Select all  Expand view
MDB2MYSQL( oCn, "c:\fwh\samples\xbrtest.mdb,mypassword", "CUSTOMER" )
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10625
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Pasar datos de una tabla DBF a una de access

Postby AIDA » Wed Aug 13, 2014 12:24 am

Regards :mrgreen:

Image


Image


Image

Saluditos :wink:
Que es mejor que programar? creo que nada :)
Atropellada pero aqui ando :P

I love Fivewin

séʌǝɹ ןɐ ɐʇsǝ opunɯ ǝʇsǝ
User avatar
AIDA
 
Posts: 879
Joined: Fri Jan 12, 2007 8:35 pm

Previous

Return to FiveWin para Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 22 guests