Schema Informations from OleDbDataReader

The OleDbDataReader Object in ADO.NET provides a stream-based, forward-only, read-only retrieval of query results from the Data Source. It is specifically designed for retrieving data and does not allow for data modification operations.

When the ExecuteReader method is executed in the OleDbCommand Object, it instantiates an OleDb.OleDbDataReader Object, which represents the result set obtained from the execution of the SQL statement.

Dim oledbReader As OleDbDataReader = oledbCmd.ExecuteReader()

While an OleDbDataReader is open and active, you have the ability to retrieve schema information about the current result set using the GetSchemaTable method. The GetSchemaTable method returns a DataTable object that is populated with rows and columns containing the schema information for the current result set.

GetSchemaTable | OleDbDataReader

By calling GetSchemaTable on the OleDbDataReader Object, you can obtain valuable metadata about the columns in the result set, such as the column name, data type, size, and other relevant properties. This schema information can be utilized for various purposes, including dynamically generating UI elements, performing data validation, or making decisions based on the structure of the result set.

The DataTable returned by GetSchemaTable contains rows that represent the columns in the result set, with each column containing information about a specific aspect of the column's schema. You can access and analyze this schema information using the methods and properties provided by the DataTable object.

Full Source VB.NET
Imports System.Data.OleDb Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim connetionString As String Dim oledbCnn As OleDbConnection Dim oledbCmd As OleDbCommand Dim sql As String connetionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Your mdb filename;" sql = "Your SQL Statement Here like Select * from product" oledbCnn = New OleDbConnection(connetionString) Try oledbCnn.Open() oledbCmd = New OleDbCommand(sql, oledbCnn) Dim oledbReader As OleDbDataReader = oledbCmd.ExecuteReader() Dim schemaTable As DataTable = oledbReader.GetSchemaTable() Dim row As DataRow Dim column As DataColumn For Each row In schemaTable.Rows For Each column In schemaTable.Columns MsgBox(String.Format("{0} = {1}", column.ColumnName, row(column))) Next Next oledbReader.Close() oledbCmd.Dispose() oledbCnn.Close() Catch ex As Exception MsgBox("Can not open connection ! ") End Try End Sub End Class
connetionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Your mdb filename;"
sql = "Your SQL Statement Here like Select * from product"

You have to replace the string with your realtime variables.