'this will serve as an open connection to our data source. Public con As OleDb.OleDbConnection = jokendb() 'this is some set of commands and a database connection that are use to fill later our datatable Dim da As New OleDb.OleDbDataAdapter 'this will represent as our table in memory Dim dt As New DataTable 'this holds our SQL Statements Dim sql As String
Public Function jokendb() As OleDb.OleDbConnection Return New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & Application.StartupPath & "\studinfo.accdb") End Function
Try sql = "SELECT ID,firstname,lastname,gender,course FROM students" con.Open() da = New OleDb.OleDbDataAdapter(sql, con) 'fill the data to datatable da.Fill(dt) 'declare a variable as DataRow which is represent a row of data Dim newrow As DataRow 'loop from each row based on the number of rows stored in dt For Each newrow In dt.Rows 'display the results in listview ListView1.Items.Add(newrow.Item(0)) 'this is for ID ListView1.Items(ListView1.Items.Count - 1).SubItems.Add(newrow.Item(1)) 'this is for Name ListView1.Items(ListView1.Items.Count - 1).SubItems.Add(newrow.Item(2)) 'this is for Lastname ListView1.Items(ListView1.Items.Count - 1).SubItems.Add(newrow.Item(3)) 'this is for gender ListView1.Items(ListView1.Items.Count - 1).SubItems.Add(newrow.Item(4)) ' this is for course Next Catch ex As Exception End Try