Imports System.Data.OleDbPublic Class DATAREADERONE 'OleDbConnection is a class used to create the connection with the backend. and con is the object of OleDbConnection. Dim con As OleDbConnection 'OleDbDataReader is abstract class used to read the data from the backend and it require open connection. Dim datareader As OleDbDataReader 'OleDbCommand is used to bind with the table of the backend. Dim cmd As OleDbCommand 'after the reterive of data it will be stored in the datatable Dim dt As New DataTable 'System.Text.StringBuilder is a class provide by .net to concatenate the string and create the line. Dim str As New System.Text.StringBuilder Private Sub DATAREADERONE_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'rtnstr is user build function used to create the connectionstring. con = New OleDbConnection(rtnstr) cmd = New OleDbCommand() 'OleDbCommand requires 3 things. ' one is commandText i.e is name of table or query or storeprocedure of backend 'second is commandtype whether we r dealing with the tableDirect or storedProcedure or sql query. 'third is connection string cmd.CommandText = "studentdetails" cmd.CommandType = CommandType.TableDirect cmd.Connection = con con.Open() 'ExceuteReader is method that will execute the command and return datareader. datareader = cmd.ExecuteReader 'ReaderToTable is method which take datareader as an argument and return the datatable. DataGridView1.DataSource = ReaderToTable(datareader) End Sub Private Function ReaderToTable(ByVal reader As OleDbDataReader) As DataTable Dim newTable As New DataTable() Dim col As DataColumn Dim row As DataRow Dim i As Integer 'This for loop is used to collect the column name and insert it into the datatable with their datatype. For i = 0 To reader.FieldCount - 1 col = New DataColumn() col.ColumnName = UCase(reader.GetName(i)) col.DataType = reader.GetFieldType(i) newTable.Columns.Add(col) Next 'It will create the row . After that row will be added in the datatable While reader.Read row = newTable.NewRow() 'data is collected from the reader. column by column For i = 0 To reader.FieldCount - 1 row(i) = reader.Item(i) Next newTable.Rows.Add(row) End While Return newTable End Function Function rtnstr() As String str.Append("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=") str.Append(AppDomain.CurrentDomain.BaseDirectory) str.Append("yogita.mdb") str.Append(";Persist Security Info=False") Return str.ToString End FunctionEnd Class