Visualizzazione dei risultati da 1 a 5 su 5
  1. #1

    [vb6] Leggere tutte le tabelle di access in ADO

    Ciao,

    uso una connessione ADO per agganciarmi ad un db :

    Dim strConnect As String
    Dim strProvider As String
    Dim strDataSource As String
    Dim strDataBaseName As String
    strProvider = "Provider= Microsoft.Jet.OLEDB.4.0;"
    strDataSource = App.Path
    strDataBaseName = "G3zero.mdb"
    strDataSource = "Data Source=" & valore & "\" & strDataBaseName
    strConnect = strProvider & strDataSource
    connConnection.CursorLocation = adUseClient
    connConnection.Open strConnect
    rsRecordset.CursorType = adOpenStatic
    rsRecordset.CursorLocation = adUseClient
    rsRecordset.LockType = adLockPessimistic

    tutto mi funziona molto bene, pero' nel tradurre una vecchia stringa che si connetteva al db con un oggetto data1.databasename
    non sono riuscito a replicare la lettura di tutte le tabelle che neel vecchio prog era
    :

    Set db = OpenDatabase(Form1.Data1.DatabaseName)
    For Each dbCiclo In db.TableDefs
    nometabella = dbCiclo.Name
    Next


    come cacchio faccio con la connessione ad inizio post a scorrere tutte le tabelle ??


    Grazie

  2. #2
    Utente di HTML.it
    Registrato dal
    Sep 2005
    Messaggi
    357
    Per leggere i nomi di tutte le tabelle presenti in un data base access puoi fare:

    codice:
            Set Rs = Db.OpenSchema(adSchemaTables)
            Do Until Rs.EOF
                If Rs("table_type") = "TABLE" Then
                    If Mid(Rs("Table_Name"), 1, 4) <> "MSys" Then
                        'qui scrivi dove metterle
                    End If
                End If
                Rs.MoveNext
            Loop
            Rs.Close
    Puoi adattarlo alle tue necessità!! Gli oggetti data1 in ADO sono stati sostituiti dagli ADODC.

  3. #3

  4. #4
    OK funge, grazie tante!!


    Dim strConnect As String
    Dim strProvider As String
    Dim strDataSource As String
    Dim strDataBaseName As String
    strProvider = "Provider= Microsoft.Jet.OLEDB.4.0;"
    strDataSource = App.Path
    strDataBaseName = "G3zero.mdb"
    strDataSource = "Data Source=" & valore & "\" & strDataBaseName
    strConnect = strProvider & strDataSource
    connConnection.CursorLocation = adUseClient
    connConnection.Open strConnect
    rsRecordset.CursorType = adOpenStatic
    rsRecordset.CursorLocation = adUseClient
    rsRecordset.LockType = adLockPessimistic


    Set rs = connConnection.OpenSchema(adSchemaTables)
    Do Until rs.EOF
    If rs("table_type") = "TABLE" Then
    If Mid(rs("Table_Name"), 1, 4) <> "MSys" Then
    'qui scrivi dove metterle
    MsgBox rs("Table_Name")
    End If
    End If
    rs.MoveNext
    Loop
    rs.Close

  5. #5
    Utente di HTML.it
    Registrato dal
    Sep 2005
    Messaggi
    357
    In questo modo:

    codice:
    Dim db As New ADODB.Connection
    Nome= App.Path & "\G3zero.mdb"
    If db.State = 1 Then cn.Close
    db.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Nome & ";Persist Security Info=False"
    Controlla se dopo app.path ci vuole la \

    Ciao

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.