[ DjordjeRd @ 18.09.2003. 17:47 ] @
Kako da testiram da li postoji neka tabela u Access bazi? Npr. lupam: ... If Exists t0309 Then ... |
[ DjordjeRd @ 18.09.2003. 17:47 ] @
[ mladenovicz @ 18.09.2003. 18:11 ] @
VB kod za rad sa ADOm
Code: Public Function TableExistsADO( _ vstrDatabaseName As String, _ vstrTableName As String _ ) As Boolean Const cCnnStr As String = "PROVIDER=Microsoft.Jet.OLEDB.3.51;Data Source=" Dim cnn As ADODB.Connection Dim rst As ADODB.Recordset On Error GoTo Proc_Err Set cnn = New ADODB.Connection cnn.ConnectionString = cCnnStr & vstrDatabaseName cnn.Open Set rst = New ADODB.Recordset rst.Open "SELECT * FROM " & vstrTableName, cnn TableExistsADO = True Proc_Exit: ' close and destroy recordset and connection object If Not rst Is Nothing Then If rst.State <> adStateClosed Then rst.Close Set rst = Nothing End If If Not cnn Is Nothing Then If cnn.State <> adStateClosed Then cnn.Close Set cnn = Nothing End If Exit Function Proc_Err: If Err.Number = -2147217865 Then ' ADO returns this error code if table doesn't exist TableExistsADO = False Resume Proc_Exit End If End Function Kad koristis DAO, cini mi se da postoji kolekcija Tables ili tako nesto, ne mogu da se setim, i ides kroz kolekciju i trazis onu koja ti treba [ DjordjeRd @ 18.09.2003. 18:14 ] @
Hvala najlepše na brzom i preciznom odgovoru. ADO je, kao i uvek, više nego dovoljan. Sve je odmah proradilo...
[ DjordjeRd @ 18.09.2003. 19:08 ] @
Eto, iskopala se i DAO varijanta:
'******************************************************** ' FUNCTION: IsTableQuery() ' ' PURPOSE: Determine if a table or query exists. ' ' ARGUMENTS: ' DbName: The name of the database. If the database name ' is "" the current database is used. ' TName: The name of a table or query. ' ' RETURNS: True (it exists) or False (it does not exist). ' '******************************************************** Function IsTableQuery(DbName As String, TName As String) As Integer Dim Db As DAO.Database, Found As Integer, Test As String Const NAME_NOT_IN_COLLECTION = 3265 ' Assume the table or query does not exist. Found = False ' Trap for any errors. On Error Resume Next ' If the database name is empty... If Trim$(DbName) = "" Then ' ...then set Db to the current Db. Set Db = CurrentDb() Else ' Otherwise, set Db to the specified open database. Set Db = DBEngine.Workspaces(0).OpenDatabase(DbName) ' See if an error occurred. If Err Then MsgBox "Could not find database to open: " & DbName IsTableQuery = False Exit Function End If End If ' See if the name is in the Tables collection. Test = Db.TableDefs(TName).Name If Err <> NAME_NOT_IN_COLLECTION Then Found = True ' Reset the error variable. Err = 0 ' See if the name is in the Queries collection. Test = Db.QueryDefs(TName$).Name If Err <> NAME_NOT_IN_COLLECTION Then Found = True Db.Close IsTableQuery = Found End Function Copyright (C) 2001-2025 by www.elitesecurity.org. All rights reserved.
|