Funzione per rilevare se il campo passato e' un INDICE database Access '******************************************************* ' questa funzione CERCA il campo e' Index ' cerca questi valori dello schema ' TABLE_NAME .. ANAGRAFICA ' INDEX_NAME .. ID ' PRIMARY_KEY .. Vero ' Unique .. Vero '******************************************************* Public Function VerificaIndex(ByVal NomeDb As String, ByVal Tabella As String, ByVal Campo As String) As String On Error GoTo Errore IndexName = "" Dim rstSchema As ADODB.Recordset Dim cnn As ADODB.Connection cnn = New ADODB.Connection cnn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0" cnn.Open(NomeDb) rstSchema = cnn.OpenSchema(ADODB.SchemaEnum.adSchemaIndexes) Dim I As Integer rstSchema.Filter = "" rstSchema.Filter = "TABLE_NAME='" & Tabella & "' and INDEX_NAME <> " & Chr(34) & Chr(34) & " and COLUMN_NAME = '" & Campo & "'" Dim Ritorno As String Ritorno = "" 'Do Until rstSchema.EOF 'Debug.Print("Type = " & rstSchema.Fields("TABLE_NAME").Value) 'Debug.Print("TABLE_CATALOG = " & rstSchema.Fields("TABLE_CATALOG").Value) 'Debug.Print("TABLE_SCHEMA = " & rstSchema.Fields("TABLE_SCHEMA").Value) 'Debug.Print("INDEX_NAME = " & rstSchema.Fields("INDEX_NAME").Value) 'Debug.Print("Type = " & rstSchema.Fields("Type").Value) 'Debug.Print("PRIMARY_KEY = " & rstSchema.Fields("PRIMARY_KEY").Value) VerificaIndex = rstSchema.Fields("COLUMN_NAME").Value 'Exit Do ' rstSchema.MoveNext() 'Loop rstSchema.Close() cnn.Close() Exit Function Errore: VerificaIndex = "" rstSchema.Close() cnn.Close() End Function |