Use this method when you need to retrieve structure of a table only, not the data.
The FillSchema method retrieves the schema from the data source using the SelectCommand. The connection object associated with the SelectCommand must be valid, but it does not need to be open. If the connection is closed before FillSchema is called, it is opened to retrieve data, then closed. If the connection is open before FillSchema is called, it remains open.
A FillSchema operation adds columns to the Columns collection of the DbDataTable, and configures DataColumn properties if they exist at the data source. FillSchema also configures the Constraints property.
FillSchema does not return any rows. Use the Fill, FillPage, or Open methods to add rows to a DbDataTable.
For more detailed information, refer to topic System.Data.Common.DataAdapter.FillSchema.
static void UseDataTable(DbDataTable myDataTable, DbConnection myConnection) { myDataTable.Connection = myConnection; myDataTable.SelectCommand = myConnection.CreateCommand(); myDataTable.SelectCommand.CommandText = "SELECT * FROM Test.Dept"; myDataTable.FillSchema(); }
Private Shared Sub UseDataTable(ByVal myDataTable As DbDataTable, ByVal myConnection As DbConnection) myDataTable.Connection = myConnection myDataTable.SelectCommand = myConnection.CreateCommand myDataTable.SelectCommand.CommandText = "SELECT * FROM Test.Dept" myDataTable.FillSchema() End Sub
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2