in
La comunità italiana dedicata a Sviluppatori e Architetti IT delle piattaforme Windows

VB6 e database foxpro 8 - Problema stringhe lette in binario

Ultimo messaggio ricevuto il 16-01-2008 9.52 da devspy. 5 risposta(e).
Pagina 1 di 1 (6 elemento/i)
Ordina messaggi: Precedente Successivo
  • 10-01-2008 21.04

    • pitsoft
    • Utente Top 500
    • Registrato il 10-01-2008
    • Grosseto
    • Messaggi 3

    VB6 e database foxpro 8 - Problema stringhe lette in binario

    Salve,
    ho un problema ad aprire con VB6 un database foxpro 8 con OLE DB.
    In pratica viene aperto correttamente senza darmi errori ma quando leggo il recordset tutti i campi di tipo alfanumerico me li interpreta come binari, rendendomi impossibile la lettura dei dati.
    Ho provato la procedura anche su altri Pc ma con lo stesso risultato.
    Questo il codice che utilizzo per la prova:

    Dim DB As New ADODB.Connection

    Dim DT As New ADOR.Recordset

    NOMEFILE = "Provider=VFPOLEDB.1;SourceType=DBF;Data Source=C:\foxpro;Collating Sequence=MACHINE;"

    DB.Open NOMEFILE

    DT.CursorType = adOpenKeyset

    XSQL = "SELECT * FROM C:\foxpro\tabstam.DBF"

    DT.Open XSQL, DB, adOpenKeyset

    DT.MoveFirst

    A$ = DT.Fields("st_descr").Value
    Label1.Caption = A$

    Quando visualizzo A$ vengono fuori una serie di punti interrogativi.
    Se dalla finestra di debug digito print DT.Fields("st_descr").Type mi restituisce 128 che corrisponde ad "adBinary".
    Anche se utilizzo l'oggetto ADO Data Control il risultato è lo stesso.
    Il driver VFPOLEDB che utilizzo è l'ultima versione (9) scaricata dal sito microsoft.
    Ho fatto la prova anche su altri database dello stesso tipo (anagrafe Studio K - SICI) ma il risultato è lo stesso
    Se qualcuno mi può aiutare anche provando, questo è un piccolo database tra quelli che non riesco correttamente ad aprire:
    http://www.pitsoft.net/dbffoxpro.zip
    Lo stesso database aperto con DBF Viewer 2000 viene visualizzato correttamente.

    Qualcuno può aiutarmi?

    • Log
  • 11-01-2008 9.24 In risposta a

    Re: VB6 e database foxpro 8 - Problema stringhe lette in binario

    Ti segnalo due procedure che eseguono un'interrogazione sul DBF un po' differente, ma dovrebbero darti qualche spunto per provare ad accedere in modo diverso e magari ovviare al problema di lettura in "binario":

    Private Function DBFQuantity() As Double

      ' Reference : Microsoft Remote Data Object 2.0
     
      Dim FXPConn As New rdoConnection
      Dim FXPRs As rdoResultset
      Dim FXPDBSQL As String
      Dim DBFileName As String, PathDBFileName As String

      DBFileName = "sample.dbf"
      PathDBFileName = App.Path

      FXPConn.Connect = "SourceType=DBF;" & _
                        "SourceDB=" & PathDBFileName & ";" & _
                        "Driver={Microsoft Visual FoxPro Driver}"

      FXPDBSQL = "SELECT * FROM " & DBFileName
      FXPConn.CursorDriver = rdUseOdbc
      FXPConn.EstablishConnection "rdDriverNoPrompt"
      Set FXPRs = FXPConn.OpenResultset(FXPDBSQL, rdOpenKeyset, rdConcurRowVer)
     
      If FXPRs.EOF Then
        DBFQuantity = 0
      Else
        DBFQuantity = FXPRs.RowCount
      End If

      FXPRs.Close
      FXPConn.Close

    End Function




    Private Function DBFQuantity() As Double

      ' Reference : Microsoft ActiveX Data Ojbects 2.0 Library
      ' Save the dbf file in the program's directory first

      Dim FXPConn As New ADODB.Connection
      Dim FXPRs As New ADODB.Recordset
      Dim FXPDBSQL As String
      Dim DBFileName As String, PathDBFileName As String

      DBFileName = "sample.dbf"
      PathDBFileName = App.Path

      FXPDBSQL = "SELECT * FROM " & DBFileName
      FXPConn.Open "Driver={Microsoft Visual FoxPro Driver};" & _
                   "SourceType=DBF;" & _
                   "SourceDB=" & PathDBFileName & ";" & _
                   "Exclusive=No"
                 
      FXPRs.CursorLocation = adUseClient ' we will use the RecordCount property

      FXPRs.Open FXPDBSQL, FXPConn, adOpenDynamic, adLockOptimistic

      If FXPRs.EOF Then
        DBFQuantity = 0
      Else
        DBFQuantity = FXPRs.RecordCount
      End If

      FXPRs.Close
      FXPConn.Close

    End Function
    • Log
  • 11-01-2008 9.27 In risposta a

    Re: VB6 e database foxpro 8 - Problema stringhe lette in binario

    Ricorda anche che è necessario che tu abbia installato una versione recente di MDAC (Microsoft Data Access Components).
    • Log
  • 11-01-2008 16.39 In risposta a

    • pitsoft
    • Utente Top 500
    • Registrato il 10-01-2008
    • Grosseto
    • Messaggi 3

    Re: VB6 e database foxpro 8 - Problema stringhe lette in binario

    Ho provato anche con il codice inviato (erano tentativi già fatti).

    In questo caso, utilizzando sia RDO che ODBC non apre nemmeno il database (che invece viene aperto con ADO) e restituisce il messaggio "Not a table".

    Premetto che come riferimenti VB ho:

    - Microsoft Activex Data Object 2.8

    - Microsoft ADO Ext. 2.8 DDL and Security

    - Microsof Data Access Component Installed Version

    - Microsoft Remote Data Object 2.0

    Pitsoft

    • Log
  • 12-01-2008 21.02 In risposta a

    • pitsoft
    • Utente Top 500
    • Registrato il 10-01-2008
    • Grosseto
    • Messaggi 3

    Re: VB6 e database foxpro 8 - Problema stringhe lette in binario - Risolto in parte

    Su un altro Forum  http://www.visual-basic.it/forum/boards.asp  ho ricevuto una soluzione parziale:

     scaricato il driver oledb di foxpro 9
    - inserito stringa di connessione:
    cnText = "Provider=VFPOLEDB.1;Data Source=E:\scambio\vb6\fox8test"
    - inserito command:
    rs.Open "SELECT st_codice, st_atto, '' + st_descr as xxxx FROM
    [tabstam.DBF]", cn, adOpenStatic, adLockReadOnly
    Da notare il '' + st_descr che ha forzato la restituzione di una stringa
    leggibile al posto della porcheria binaria

    • Log
  • 16-01-2008 9.52 In risposta a

    Re: VB6 e database foxpro 8 - Problema stringhe lette in binario - Risolto in parte

    Interessante! Spero tu riesca a trovare una soluzione ed a pubblicarla sul forum. Stick out tongue
    • Log
Pagina 1 di 1 (6 elemento/i)
Prelevato da http://www.devspy.com/forums/t/4656.aspx
DevSpy.com 6.0 © 2001-2008 - Alcuni Diritti Riservati
Salvo diversa indicazione, tutti i contenuti sono pubblicati sotto licenza "Creative Commons Attribution-Share Alike 3.0"