ADODB.SchemaEnum.adSchemaIndexes





OpenSchema(ADODB.SchemaEnum.adSchemaIndexes)

' Apre una connessione ADODB per leggere il nome dei campi Contatore, PrimaryKey e Index


Dim ADOCon1 As ADODB.Connection
Dim X As Integer
Dim strConnect As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & strDBLocation & ";Persist Security Info=False"
Dim rstSchema As ADODB.Recordset

ADOCon1 = New ADODB.Connection
With ADOCon1
.ConnectionString = strConnect
.Open()
End With

' Apre un Recordset per la ricerca di campi Autoincrement


Dim RsAutoIncrement As ADODB.Recordset
RsAutoIncrement = New ADODB.Recordset
RsAutoIncrement.let_ActiveConnection(ADOCon1)
RsAutoIncrement.CursorLocation = ADODB.CursorLocationEnum.adUseServer
RsAutoIncrement.CursorType = ADODB.CursorTypeEnum.adOpenStatic
RsAutoIncrement.Open(NomeTabella)


For intCounter2 = 0 To intFieldCount - 1

' scrittura file di testo con il nome tabella-Nomecampo-tipo


Dim Mtipo As String = TipoCampo((rstTable.Fields(intCounter2).Type))



System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor
Rs.AddNew()
Rs.Fields("IdTabella").Value = IdTabella
Rs.Fields("Campo").Value = rstTable.Fields(intCounter2).Name
Debug.Print(Rs.Fields("Campo").Value)



' ' ****************************************

' ' SE E UN CAMPO CONTATORE INSERISCE TRUE

' '*****************************************


' ricerca di campi Autoincrement (contatore)


For X = 0 To RsAutoIncrement.Fields.Count - 1

If RsAutoIncrement.Fields(X).Properties("ISAUTOINCREMENT").Value = True And RsAutoIncrement.Fields(X).Name = rstTable.Fields(intCounter2).Name Then
Debug.Print(rstTable.Fields(intCounter2).Name)


Rs.Fields("Contatore").Value = True
Exit For
End If

If RsAutoIncrement.Fields(X).Name = rstTable.Fields(intCounter2).Name Then
Exit For
End If


Next X



' ****************************************

' SE E UN CAMPO primarykey INSERISCE TRUE

'*****************************************


rstSchema = New ADODB.Recordset
rstSchema = ADOCon1.OpenSchema(ADODB.SchemaEnum.adSchemaIndexes)
rstSchema.MoveFirst()



'*************************

' ricerca primarykey

'*************************


rstSchema.Filter = ""
rstSchema.Filter = "TABLE_NAME='" & NomeTabella & "' and PRIMARY_KEY = True" '& Chr(34) & Chr(34)

If Not rstSchema.EOF Then
Do While Not rstSchema.EOF
If (rstSchema.Fields("COLUMN_NAME").Value) = rstTable.Fields(intCounter2).Name Then
'MsgBox("Cle' primaire de la table " & tableName & ": " & Rs.Fields("COLUMN_NAME").Value, MsgBoxStyle.Information, "Primary keys")

Rs.Fields("PrimaryKey").Value = True
Rs.Fields("Ricerca").Value = True
Exit Do
End If

rstSchema.MoveNext()
Loop

End If


' ****************************************

' SE E UN CAMPO indice INSERISCE TRUE

'*****************************************

rstSchema.Filter = ""
rstSchema.Filter = "TABLE_NAME='" & NomeTabella & "' and INDEX_NAME <> '' and COLUMN_NAME = '" & rstTable.Fields(intCounter2).Name & "'"
If Not rstSchema.EOF Then
Rs.Fields("Index").Value = True
Rs.Fields("Ricerca").Value = True
End If


System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default

IndexName = ""


If Mtipo <> "Non Definito" Then
Rs.Fields("Tipo").Value = Mtipo
Else
Rs.Fields("Tipo").Value = "Long"
End If

Rs.Fields("Lungo").Value = rstTable.Fields(intCounter2).DefinedSize

Rs.Update()

Next intCounter2

End If
End With

Next intCounter1










( adodbschemaenumadschemaindexes.html )- by Paolo Puglisi - Modifica del 17/12/2023