Hi guys

ok guys this is my problem my DataGridView1 does not show the data on my testdb.mdb i need to fix this first before i continue on adding records on my db i very much appreciate any one who can help me with this.

Imports System.Data.OleDb

Public Class Customer

    Dim con As OleDbConnection

    Private Sub Customer_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\testdb.mdb"
        con.Open()
        con.Close()
        showItems()

    End Sub

    Private Sub showItems()

        Dim dt As New DataTable
        Dim ds As New DataSet
        ds.Tables.Add(dt)
        Dim da As New OleDbDataAdapter
        con.Open()
        da = New OleDbDataAdapter("Select * from customer", con)
        da.Fill(dt)

        DataGridView1.DataSource = dt.DefaultView
        con.Close()


    End Sub
End Class

I think this will do.

Dim cmd As New OleDbCommand
Dim con As New OleDbConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\testdb.mdb"
Dim dt As New OleDbDataAdapter
Dim ds As New DataSet

Private Sub Customer_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
	showItems()
End Sub

'This will bind database to your datagridview 
Private Sub ShowItems()
	cmd = ('your query: Select * from customer', con)
	con.Open()
	dt = OleDbDataAdapter(cmd)
	dt.fill(ds, 'your table name')
	DataGridView1.DataSource = ds.Tables('your table name').DefaultView
	con.Close()
End Sub

'This will read records from your database
Private Sub ReadRecord()
	cmd = ("Select * from customer", con)
      con.Open()
       Dim dr As OleDbDataReader = cmd.ExecuteReader()
	While
	  'Your code here
	End While
	dr.Close()
	con.Close()
End Sub

I might be forgetting something but hopefully this will help

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.