Get the name and type of column of a table

Friday, December 26, 2008

   Public sub GetColumns(ByVal sTableName As String, ByVal ListBoxObject As ListView) 
               
                Dim iCount As Integer
                Dim ObjListviewItem As ListViewItem
                Dim sSQL As String = "Select * From " & sTableName & " Where 1 = 2"
                Dim oCmd As Odbc.OdbcCommand = New OdbcCommand(sSQL, ObjCon)               
                Dim oRS As Odbc.OdbcDataReader = oCmd.ExecuteReader
                ListBoxObject.Items.Clear()
                For iCount = 0 To oRS.FieldCount - 1
                    ObjListviewItem = ListBoxObject.Items.Add(oRS.GetName(iCount), 0)
                    ObjListviewItem.SubItems.Add(oRS.GetFieldType(iCount).ToString)
                Next iCount
                oRS.Close()              
            Catch ex As Exception
               msgbox( Err.Description)
            End Try
        End Function
    End Class

0 comments

Post a Comment