I have two forms "Sales" and "PurCh". The datagridview in the Sales form is being populated by a stored procedure that is carried out when the form loads and it works perfectly. But the datagridview from the "PurCh" form has refused to populate when the form loads. I initially thought the load event was not firing but then tested it by placing a message box which at runtime popped up. I dont know whats wrong with my code.

Here is the code on the sales form

Imports System.Data.OleDb
Public Class Sales
    Dim con As New OleDbConnection

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

        'Connection String
        con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\ABCFarm.mdb"

        con.Open()
        RefreshDgv()

    End Sub
    Private Sub RefreshDgv()
        Dim da As New OleDb.OleDbDataAdapter("SELECT * FROM Sales ", con)
        Dim dt As New DataTable
        'fill data to datatable
        da.Fill(dt)

        'offer data in data table into datagridview
        dgvSales.DataSource = dt

        'close connection
        con.Close()
    End Sub

Here is my code for PurCh Form

Imports System.Data.OleDb
Public Class PurCh
    Dim con As OleDbConnection

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

        'Connection String
        con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\ABCFarm.mdb"

        con.Open()
        RefreshDgv()

    End Sub
    Private Sub RefreshDgv()
        Dim da As New OleDb.OleDbDataAdapter("SELECT * FROM Purchases ", con)
        Dim dt As New DataTable
        'fill data to datatable
        da.Fill(dt)

        'offer data in data table into datagridview
        dgvPurchase.DataSource = dt

        'close connection
        con.Close()
    End Sub
End Class

Please help me. im writting my Final diploma exams and have been instructed to write a program with VB.net 2008 and Access DB 2000 to Manage a Poultry farm.
Thanks

Does the DataGridView in the sales form have AutoGenerateColumns enabled while the Purchase does not?

Its fixed now. I just deleted the Purchase form and started afresh and it worked with this code

Imports System.Data.OleDb
Public Class frmPurchase
    Dim con As New OleDbConnection
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Connection String
        con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\ABCFarm.mdb"

        con.Open()
        RefreshDgv()
    End Sub
    Private Sub RefreshDgv()
        Dim da As New OleDb.OleDbDataAdapter("SELECT * FROM Purchases ", con)
        Dim dt As New DataTable
        'fill data to datatable
        da.Fill(dt)

        'offer data in data table into datagridview
        DataGridView1.DataSource = dt.DefaultView

        'close connection
        con.Close()
    End Sub
End Class

Thanks

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.