Programación General > Visual Basic 6.0 e inferiores

 Cuantas Tablas Tiene La Base De Datos?

(1/2) > >>

calosoft:
hola, estoy desarrolando un programita, donde tengo un combo y quiero que en ese combo aparescan los nombres de las tablas de mi base de datos.
mi base de datos esta en access, y las tablas se van generando con otros procesos del programita. alguien me puede ayudar?, y si saben como se hace esto, me lo podrian decir como se hace en sql server 2000

ArKaNtOs:
mmmmm hola yo tambien busco lo mismo carlosoft me acuerdo que tenia el codigo guardado en el servidor de mi universidad pero tuvo un fallo y lo tuvieron que formatear y ahora no se que hacer :P, lo peor es que ya no me acuerdo de como hacerlo  :unsure: si alguien sabe como hacerlo le pido de favor que lo pase plz

Widark:
Que tal!


--- Código: Text ---Dim Cnx As ADODB.ConnectionDim pth As String          'Database PathDim Ctl    As ADOX.Catalog 'Database Catalog from Actual ConnectionDim CtlTbl As ADOX.TableDim Col    As ADOX.ColumnDim sGen As StringDim i    As IntegerDim j    As IntegerDim k    As Integer Private Sub cmdConectar_Click()On Error GoTo ErrGetPath   ' Establece CancelError a Verdadero  cdlBasedatos.CancelError = True  ' Establece banderas  cdlBasedatos.Flags = cdlOFNHideReadOnly  ' Establece filtros  cdlBasedatos.Filter = "All Files(*.*)|*.*|Access 2000 DB (*.mdb)|*.mdb"  ' Especifica filtro por defecto  cdlBasedatos.FilterIndex = 2  cdlBasedatos.ShowOpen  pth = cdlBasedatos.FileName  If LenB(pth) > 0 And LenB(Dir(pth)) > 0 Then    Coneccion    If Not (Cnx Is Nothing) Then      LlenaTabla    End If  End If  Exit Sub  ErrGetPath:  'User pressed the Cancel button  pth = vbNullStringEnd Sub Sub Coneccion()   On Error GoTo CnnError  Dim strCnn As String    strCnn = "Provider=Microsoft.Jet.OLEDB.4.0;"  strCnn = strCnn & "Data Source=" & pth & ";"  strCnn = strCnn & "Jet OLEDB:Engine Type=5;"    Set Cnx = New ADODB.Connection  Cnx.Open strCnn  Exit Sub  CnnError:Dim psw As String   Select Case Err    Case Is = -2147217843 'Database password incorrect      psw = ObtainPassword      strCnn = vbNullString      strCnn = "Provider=Microsoft.Jet.OLEDB.4.0;"      strCnn = strCnn & "Data Source=" & pth & ";"      strCnn = strCnn & "Jet OLEDB:Engine Type=5;"      strCnn = strCnn & psw      If LenB(psw) = 0 Then        Resume Next      Else        Resume      End If    Case Else      MsgBox "Error Number : " & Err & vbCrLf & Error, vbCritical, Err.Source      End  End SelectEnd Sub Sub LlenaTabla()    On Error GoTo ErrorTab    Screen.MousePointer = vbHourglass    Set Ctl = New ADOX.Catalog  Ctl.ActiveConnection = Cnx  i = 0  'Table Definitions  For Each CtlTbl In Ctl.Tables    If CtlTbl.Type = "TABLE" Then      lstTablas.AddItem CtlTbl.Name    End If  Next    Screen.MousePointer = vbDefault  Exit Sub  ErrorTab:  MsgBox Err.Description, vbCritical  Screen.MousePointer = vbDefaultEnd Sub Private Function ObtainPassword() As String    Dim psw As String    psw = vbNullString    Do While Len(psw) = 0    frmLogin.Show vbModal    psw = frmLogin.Password    If frmLogin.NoMore Then      ObtainPassword = vbNullString      Exit Do    End If  Loop  If Len(psw) > 0 And (Not frmLogin.NoMore) Then    ObtainPassword = ";Jet OLEDB:Database Password=" & psw & ";"    Unload frmLogin  Else    MsgBox "Entre el password correcto.", vbExclamation    ObtainPassword = vbNullString    Set Cnx = Nothing    Unload frmLogin  End IfEnd Function Este es un ejemplo que descargue de freecode y utiliza ADOX. Este es con DAO
--- Código: Text ---Private Sub cmdBasedatos_Click()Dim tblObj As TableDefOn Error GoTo errCancelCommon    Abierto = False    Adiciono = False    cdlBasedatos.CancelError = False    cdlBasedatos.ShowOpen    If Len(cdlBasedatos.FileName) <> 0 Then        cmdCodigos.Enabled = True        On Error Resume Next        Set Cnx = New ADODB.Connection        With Cnx            For i = 0 To 5 Step 0.1                .CursorLocation = adUseClient                .ConnectionString = "Provider=Microsoft.Jet.OLEDB." & Replace(Format(i, "0.0"), ",", ".") & ";Persist Security Info=False;Data Source=" & cdlBasedatos.FileName & ";Jet OLEDB:Database Password=;"                .Open                If .State = 1 Then Exit For            Next            If .State = 0 Then                MsgBox "No se encontró una versión adecuada para iniciar el motor de la BD.", vbCritical, "Error al iniciar"                .Close                End              Else                Abierto = True                cmbTablas.Clear                'Abró la base de datos y lo asigno a la variable                Set gdbCurrentDB = DBEngine.OpenDatabase(cdlBasedatos.FileName, False, False, ";pwd=")                                For Each tblObj In gdbCurrentDB.TableDefs                    If (tblObj.Attributes And dbSystemObject) = 0 Then 'Valido que las tablas no sean del sistema, adiciono al combo                        cmbTablas.AddItem tblObj.Name                    End If                Next            End If        End With    End If    Exit SuberrCancelCommon:    End Sub Espero les sirva

ArKaNtOs:
Thanx Widark :) lo probare, espero me funcione

calosoft:
gracias Widark, me salvaste de una, funciona el primer codigo, el segundo nu lo probe, te pasaste won  :smartass:

Navegación

[0] Índice de Mensajes

[#] Página Siguiente

Ir a la versión completa