Learning About Fields
If you know that a table exists in a database, learning about the fields it contains is relatively easy. The following sections describe several ways a program can obtain information about the table’s fields.
Filling a DataTable
One method to get information about a table’s fields is to use a data adapter to fill a DataTable with the results of the query SELECT * FROM table_name . The DataTable object’s Columns collection contains information about the table even if the query returns no records.
Example program TableColumns, shown in Figure 13.1, demonstrates this technique. The program uses the code in Listing 13.1 to display information about a table’s columns.
Figure 13.1. Program TableColumns uses a data adapter ...
Get Visual Basic® .NET Database Programming now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.