Visualizzazione post con etichetta database. Mostra tutti i post
Visualizzazione post con etichetta database. Mostra tutti i post

venerdì 12 giugno 2009

ricavare tipo dei campi dal database

Per ricavare il tipo dei campi dal database basta eseguire la seguente procedura

public sub RicavaCampi()
Dim dtType As DataTable = getTables()
For Each row As DataRow In dtType.Rows
If Not row(2).Equals("sysdiagrams") Then
Dim res(3) As String
res(2) = row(2) 'nome della tabella
If res(2).Equals("Categories") Then
Dim dtCol As DataTable = _Connection.GetSchema("Columns", res)
If dtCol.Rows.Count > 0 Then
dim colName as string

dim colType as string
For Each col As DataRow In dtCol.Rows
colName = col("COLUMN_NAME")
colType = col("DATA_TYPE")
Next
End If
End If
End If
Next
end sub



Public Function getTables() As DataTable
_Connection.Open()
If Not IsNothing(_Connection) Then
Dim restriction(3) As String
restriction(3) = "BASE TABLE"
Dim dtTables As DataTable = _Connection.GetSchema("Tables", restriction)

Return dtTables
Else
Throw New Exception("Nessuna Connessione attiva...")
End If
_Connection.Close()
End Function